如何使用从服务调用的Dialog中的ACTION_SEND意图?

时间:2015-08-24 22:55:36

标签: android android-intent android-context

我的应用程序使用系统警报对话框在服务的帮助下创建聊天头。现在我在该对话框中有一些图像,并希望使用intent分享它们。

但我得到的错误是:

  

android.util.AndroidRuntimeException:从中调用startActivity()   在Activity上下文之外需要   FLAG_ACTIVITY_NEW_TASK   旗。这真的是你想要的吗?

如何解决这个问题?

用于共享图像的代码是:

gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v,
                                int position, long id) {

            //Toast.makeText(cont,"hola",Toast.LENGTH_SHORT).show();

            Uri uri = imageAdapter.getUri(position);
            Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
            sharingIntent.setType("image/jpeg");
            sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
            sharingIntent.setPackage("com.whatsapp");
            sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            context.startActivity(Intent.createChooser(sharingIntent, ""));

        }
    });

1 个答案:

答案 0 :(得分:0)

最后我自己纠正了。 正确的代码是:

<div class="cover_bgr"></div>
<div class="main">
    <a href="#"class="btn">Click</a>
</div>