我使用下面的代码通过其他应用分享照片并打印他们的包名:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/jpeg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(FilePath));
PackageManager packageManager = this.getPackageManager();
List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(sharingIntent, PackageManager.MATCH_DEFAULT_ONLY);
int i = 0;
while(i < resolveInfo.size()) {
System.out.println(i + " " + resolveInfo.get(i).activityInfo.packageName);
i++;
}
startActivity(Intent.createChooser(sharingIntent, "Share");
并得到以下9个可以分享照片的包名:
06-19 16:55:22.460: I/System.out(13020): 0 com.amazon.kindle
06-19 16:55:22.460: I/System.out(13020): 1 com.android.bluetooth
06-19 16:55:22.460: I/System.out(13020): 2 com.google.android.apps.uploader
06-19 16:55:22.460: I/System.out(13020): 3 com.ecareme.asuswebstorage
06-19 16:55:22.460: I/System.out(13020): 4 com.google.android.talk
06-19 16:55:22.460: I/System.out(13020): 5 com.google.android.gm
06-19 16:55:22.460: I/System.out(13020): 6 com.aripollak.picturemap
06-19 16:55:22.460: I/System.out(13020): 7 com.instagram.android
06-19 16:55:22.460: I/System.out(13020): 8 com.facebook.katana
如果我想在选择应用时过滤一些应用。
例如,我想从共享应用列表中过滤 facebook 应用。
我怎么能dd
最佳答案
我找到了方法,但不确定这是不是最好的方法。
我的方法如下:
首先,删除行
startActivity(Intent.createChooser(sharingIntent, "Share");
其次,我从列表 resolveInfo 中删除要过滤的应用程序,如下所示:
for(i = resolveInfo.size(); i >= 0; i--) {
if((resolveInfo.get(i).activityInfo.packageName).equals("com.facebook.katana")) {
resolveInfo.remove(i);
}
}
第三,创建自己的应用程序选择器以显示 ListView 对话框以显示 resolveInfo 的项目、resolveInfo.get(i).activityInfo.loadLabel(pm)
和 resolveInfo.get(i)。 activityInfo.loadIcon(pm)
,应用名称和图标resid。
最后,如果点击项目 i,然后使用下面的代码分享照片:
Intent mysharingIntent = new Intent(Intent.ACTION_SEND);
mysharingIntent.setType("image/jpeg");
mysharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(FilePath));
mysharingIntent.setPackage(resolveInfo.get(i).activityInfo.packageName);
startActivity(mysharingIntent);
关于android - 如何在 Android 上分享照片时过滤应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17187212/