0

我有以下代码来检查支持的意图。当我检查电子邮件支持时,代码在模拟器上的行为与预期一致。当我在我的实际设备 HTC Wildfire 和三星 Galaxy Nexus 上运行相同的程序时,isEmailSupported方法返回 false。

public static boolean isEmailSupported(Context context) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, "example@example.com");
    emailIntent.putExtra(Intent.EXTRA_TEXT, "Lorem ipsum...");
    return isIntentSupported(context, emailIntent);
}

public static boolean isIntentSupported(Context context, Intent intent) {
    PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> intentActivities = packageManager.queryIntentActivities(
            intent, PackageManager.MATCH_DEFAULT_ONLY);
    return intentActivities != null && intentActivities.size() > 0;
}

任何指针将不胜感激。提前致谢。

4

1 回答 1

1

尝试添加您忘记包含在ACTION_SEND Intent. 您必须setType()使用您要放入的内容的 MIME 类型进行调用EXTRA_TEXT(在这种情况下,显然是text/plain)。

于 2012-06-09T11:16:57.933 回答