3

I need to share an image from my RecyclerAdapter because the image does not initially exist, i.e. is loaded within the Activity making use of the adapter. How can I share the bitmap to social media? Every time I click share in my app it says "No apps can perform this action".

feedItemView.setFeedSocialShareClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Share to Social Media

                ImageView imageView = (ImageView) feedItemView.findViewById(R.id.image);
                Drawable mDrawable = imageView.getDrawable();
                Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();

                String path = MediaStore.Images.Media.insertImage(context.getContentResolver(),
                        mBitmap, "Design", null);

                Uri uri = Uri.parse(path);

                Intent share = new Intent(Intent.ACTION_SEND);
                share.setType("image");
                share.putExtra(Intent.EXTRA_STREAM, uri);
                share.putExtra(Intent.EXTRA_TEXT, "I found something cool!");
                context.startActivity(Intent.createChooser(share, "Share Your Design!"));
            }
        });
Martin Erlic
  • 5,467
  • 22
  • 81
  • 153

2 Answers2

5

try with

 share.setType("image/*");
Angel Koh
  • 12,479
  • 7
  • 64
  • 91
  • Fantastic. Wow. That was wracking my brain for a while. Haha. I'll accept answer in 9 minutes when it lets me. Does the /* account for different image extensions? – Martin Erlic Mar 13 '16 at 04:35
  • 1
    exactly. you can define specific types like 'png', 'gif', etc. – Angel Koh Mar 13 '16 at 04:40
0

In Kotlin, if your SDK below 29: where you need give the address of your file!

val share = Intent(Intent.ACTION_SEND)
          share.type = "image/jpeg"
          share.putExtra(Intent.EXTRA_STREAM,Uri.parse(file.path) ) // or Uri.fromFile(file)
          share.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
          share.flags = Intent.FLAG_GRANT_WRITE_URI_PERMISSION
          startActivity(Intent.createChooser(share, "Share Image"))

But if you want cover all SDK , it's better use FileProvider

Mori
  • 2,653
  • 18
  • 24