Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自intentservice的Android共享意图_Android_Android Intent_Service_Share_Intentservice - Fatal编程技术网

来自intentservice的Android共享意图

来自intentservice的Android共享意图,android,android-intent,service,share,intentservice,Android,Android Intent,Service,Share,Intentservice,我想将多个图像从我的应用程序共享到其他应用程序。在Android的开发者页面上,我发现: Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE); shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, SavedImages); shareIntent.setType

我想将多个图像从我的应用程序共享到其他应用程序。在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错误而崩溃:

从活动上下文外部调用startActivity需要标记\u Activity\u NEW\u TASK

所以我补充说

shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
但我仍然会遇到同样的错误,我的应用程序崩溃了

如何使用intentservice中的共享意图?

这行代码

startActivity(Intent.createChooser(shareIntent, "Share images to.."));
这意味着您创建了一个意图对象,该对象用于启动对话活动,以便用户选择要处理您的shareIntent的活动。因此,在这种情况下,显示选择器对话框活动的意图需要标记\u activity\u NEW\u TASK 您可以尝试:

Intent chooserIntent = Intent.createChooser(shareIntent, "Share images to..");
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(chooserIntent);
这行代码

startActivity(Intent.createChooser(shareIntent, "Share images to.."));
这意味着您创建了一个意图对象,该对象用于启动对话活动,以便用户选择要处理您的shareIntent的活动。因此,在这种情况下,显示选择器对话框活动的意图需要标记\u activity\u NEW\u TASK 您可以尝试:

Intent chooserIntent = Intent.createChooser(shareIntent, "Share images to..");
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(chooserIntent);

如何从intentservice使用此代码你不知道现在弹出一个活动是否合适,因为当你的IntentService在后台工作时,用户可能会停止做其他事情。我知道用户可以做其他事情,但我还是想使用代码…我如何从IntentService使用此代码你不知道现在弹出一个活动是否合适,因为当你的IntentService在后台工作时,用户可能会停止做其他事情。我知道用户可以做其他事情,但我还是想使用代码。。。