微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 如何过滤(共享)电子邮件意图的特定应用程序?

我在我的应用程序中使用Action Send和createChooser API通过各种电子邮件应用程序共享一些文本消息.但我不想要我在我的设备中安装的所有应用程序.我希望特别是facebook,Gmail和Twitter在该选择器中List.How像这样过滤?谢谢

String TEXT = "I shared the file " + " via MyApp";
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/plain");
    sendIntent.putExtra(Intent.EXTRA_TEXT,TEXT);
    startActivity(Intent.createChooser(sendIntent,"Share the program:"));

这是我正在使用的代码.

解决方法

如果您知道,您需要哪些应用程序,则可以在对话框中创建自己的选择器,并根据用户的选择激发特定意图.

您可以通过调用PackageManager的queryIntentActivities来检查可用的应用程序:

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
List pkgAppsList = context.getPackageManager().queryIntentActivities( sendIntent,0);

然后选择所需的并弹出对话框.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐