在Android上分享第三个应用程序的照片

时间:2014-03-04 06:04:08

标签: android android-intent

我使用下面的代码来获取共享应用程序:

PackageManager packageManager = this.getPackageManager();
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/jpeg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(PhotoPath));
List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(sharingIntent, PackageManager.MATCH_DEFAULT_ONLY);

我得到所有应用程序选择器如下:
enter image description here
我使用下面的代码启动应用程序:
“one”表示选定的ResolveInfo。

Intent MySharingIntent = new Intent(Intent.ACTION_SEND);
MySharingIntent.setType("image/jpeg");
MySharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(PhotoPath));
MySharingIntent.setPackage(one.activityInfo.packageName);
startActivity(MySharingIntent);

如果我选择“照片”或“Google+”项目 它将弹出对话框:
enter image description here
但是我想直接启动应用程序“Photo” 没有第二个选择对话框 我该怎么做?

1 个答案:

答案 0 :(得分:1)

您可以通过添加

来完成此操作

intent.setComponent(new ComponentName("packagename of the activity","classname.java"));

但这是推荐,你必须先检查&#34;照片&#34;确实安装在设备上。