我需要检查设备上是否安装了电子邮件客户端。我使用了以下代码,但它对我不起作用。
public boolean isIntentAvailable() {
final PackageManager packageManager = getApplicationContext().getPackageManager();
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, "vin@gmail.com");
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.GET_META_DATA);
return list.size() > 0;
}
答案 0 :(得分:13)
使用此功能,对我有用:
public static boolean isMailClientPresent(Context context){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
final PackageManager packageManager = context.getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, 0);
if(list.size() == 0)
return false;
else
return true;
}
答案 1 :(得分:3)
对于电子邮件客户端,具体来说,您应该使用:
//ws:validarLogin[password='admin']/login
而不是:
intent.setType("message/rfc822");
答案 2 :(得分:0)
使用此方法:
private fun sendEmail(to: Array<String>) {
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:") // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, to)
// intent.putExtra(Intent.EXTRA_SUBJECT, subject)
if (intent.resolveActivity(requireContext().packageManager) != null) {
startActivity(intent)
}
}
要在定位api 30时能够检查电子邮件客户端,请将“查询”添加到清单中:
<queries>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="*" />
</intent>
</queries>