我正在使用:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("image/jpeg");
(...)
分享在我的应用程序中生成的图像。我想将自定义操作(将图像保存到图库)添加到由
创建的 IntentIntent.createChooser(i, "...");
我正在考虑为 android.intent.action.SEND 操作添加带有 intent-filter 的 Activity ,但这将使我的 Activity 可见并可供所有应用程序使用。我可以将 setType("image/jpeg") 更改为 setType("image/*") 并添加
<data android:mimeType="image/foobar">
到 intent-filter,但这将使我的 Activity 对所有请求 image/* 的应用程序可见。
是否有任何方法可以通过调用程序包名称(或其他可以区分我的应用程序与其他应用程序的名称)来过滤操作可见性?
最佳答案
Android 有一个很好的解决方案来满足这个要求,诀窍是 Intent.EXTRA_INITIAL_INTENTS
:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/jpeg");
List<Intent> myAddedIntents = new ArrayList<Intent>();
Intent myIntent = new Intent(...);
myAddedIntents.add(myIntent);
Intent chooserIntent = Intent.createChooser(intent, "Send via:");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
myAddedIntents.toArray(new Parcelable[] {}));
startActivity(chooserIntent);
关于android - 将仅在特定应用程序中可见的操作添加到 ACTION_SEND?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8668545/