先来看看实现效果:
也不过多介绍了,直接上代码:
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");}}