在android中的whatsapp上分享图像

时间:2014-03-18 11:22:25

标签: android whatsapp

我想分享什么样的应用程序和聊天....等等......... 我在gridview上有图像....每个图像点击必须是开放共享选项.. 但是我累了这个代码..... plz帮助我.....和任何想法..... 和我的代码如下。

grid_view.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View paramView, int position, long id) {
        String path=String.valueOf(position);
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);

        Uri screenshotUri = Uri.parse(path);
        sharingIntent.setType("image/*");
        if (sharingIntent !=null) {
            sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
            sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource:///drawable/" +path + ".jpg"));
            sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(Intent.createChooser(sharingIntent, "Share image using"));    
        }
        else {
            Toast.makeText(getApplication(), "Plase try agian", 2000).show();
        }

    }
});    

2 个答案:

答案 0 :(得分:1)

以下是分享意图的代码。

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));    

Intent sendIntent = new Intent(Intent.ACTION_SEND);     

sendIntent.setType("image/png");
sendIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(mScreenshotPath+"/"+curentDateandTime+".png")));
startActivityForResult(sendIntent, 0);

答案 1 :(得分:0)

尝试此代码将支持使用多个选项共享图像

Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file)); // Add image path
startActivity(Intent.createChooser(share, "Share image using"));