先来看看实现效果:
也不过多介绍了,直接上代码:
private void openMail() {
Uri uri = Uri.parse("mailto:" + "");
List<ApplicationInfo> applicationInfoList = getPackageManager().getInstalledApplications(PackageManager.MATCH_UNINSTALLED_PACKAGES);//获取手机应用所有包名
List<String> tempPkgNameList = new ArrayList<>();
List<Intent> emailIntents = new ArrayList<>();
for (ApplicationInfo info : applicationInfoList) {
String pkgName = info.packageName;
if (!tempPkgNameList.contains(pkgName)) {
tempPkgNameList.add(pkgName);
Intent intent = getPackageManager().getLaunchIntentForPackage(pkgName);
emailIntents.add(intent);//添加邮箱类型应用
}
}
if (!emailIntents.isEmpty()) {
String[] email = {"xxxx@qq.com"};
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra(Intent.EXTRA_EMAIL, email); // 收件人
intent.putExtra(Intent.EXTRA_SUBJECT, "这是邮件的主题部分"); // 主题
intent.putExtra(Intent.EXTRA_TEXT, "这是邮件的正文部分"); // 正文
Intent chooserIntent = Intent.createChooser(intent, "意见反馈");
if (chooserIntent != null) {
startActivity(chooserIntent);
} else {
Log.d("openEmail","没有邮箱类型应用1");
}
} else {
Log.d("openEmail","没有邮箱类型应用2");
}
}
更多【编程技术-安卓调用手机邮箱应用发送邮件】相关视频教程:www.yxfzedu.com