我想将我的应用中的多张图片分享给其他应用。在 Android 的开发者页面上,我发现:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, SavedImages);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share images to.."));
如何从 intentservice 使用此代码? 使用 intentservice 中的示例代码时,我的应用程序因 logcat 错误而崩溃:
Calling startActivity from outside of an Activity context requires the flag FLAG_ACTIVITY_NEW_TASK
所以我加了
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
但我仍然遇到同样的错误,我的应用程序崩溃了。
如何使用 intentservice 的共享 intent?
最佳答案
这行代码
startActivity(Intent.createChooser(shareIntent, "Share images to.."));
这意味着您创建了一个 Intent 对象,该对象用于启动对话 Activity ,供用户选择哪个 Activity 来处理您的 shareIntent。因此,在这种情况下,显示选择器对话框 Activity 的 Intent 需要标志 FLAG_ACTIVITY_NEW_TASK
你可以试试:
Intent chooserIntent = Intent.createChooser(shareIntent, "Share images to..");
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(chooserIntent);
关于Android 从 intentservice 共享 intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19213094/