![](/img/trans.png)
[英]How to share the image file from your own app through Instagram, Whatsapp or maybe any social app?
[英]How to exclude your own app from the Share menu?
该应用程序有一个intent过滤器,允许它通过ACTION_SEND意图出现在其他应用程序的共享菜单中。 应用程序本身也有一个使用ACTION_SEND和createChooser()的共享菜单,我的应用程序出现在列表中。 由于他们已经在我的应用程序中,让他们能够分享回自己似乎很奇怪。
如果我的应用程序从我的应用程序中调用,我的应用程序是否有办法不显示在列表中?
这是你的解决方案。 如果要排除自己的应用程序,可以使用ctx.getPackageName()更改“packageNameToExclude”
public static Intent shareExludingApp(Context ctx, String packageNameToExclude, String imagePath, String text) {
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/*");
List<ResolveInfo> resInfo = ctx.getPackageManager().queryIntentActivities(createShareIntent(text,new File(imagePath)), 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
Intent targetedShare = createShareIntent(text,new File(imagePath));
if (!info.activityInfo.packageName.equalsIgnoreCase(packageNameToExclude)) {
targetedShare.setPackage(info.activityInfo.packageName);
targetedShareIntents.add(targetedShare);
}
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0),
"Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
targetedShareIntents.toArray(new Parcelable[] {}));
return chooserIntent;
}
return null;
}
private static Intent createShareIntent(String text, File file) {
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/*");
if (text != null) {
share.putExtra(Intent.EXTRA_TEXT, text);
}
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
return share;
}
如果我的应用程序从我的应用程序中调用,我的应用程序是否有办法不显示在列表中?
不是通过createChooser()
。 您可以通过PackageManager
和queryIntentActivities()
创建自己的类似选择器的对话框,并以这种方式过滤自己。
你应该用
Intent chooserIntent = Intent.createChooser(new Intent(), "Select app to share");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.