4

I am trying to share an image from my drawable folder. It worked before but now for some reason whenever I try to share I will select the person to share it to, and it will give me an message that says: "file format is not supported". For some reason I can't share it with Whatsapp, but I can share it with another app like snapchat. So I know it is getting the correct image.

Here is my sharing code:

Uri imageUri;
imageUri = Uri.parse("android.resource://" + getPackageName() + "/drawable/" + "image" + String.valueOf(mViewPager.getCurrentItem() + 1));
//imageUri = Uri.parse("android.resource://" + getPackageName() + R.drawable.image1);
Log.d("Sharing", "android.resource://" + getPackageName() + "/drawable/" + "image" + String.valueOf(mViewPager.getCurrentItem() + 1));
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
//sharingIntent.putExtra(Intent.EXTRA_TEXT, "Ha Ha! Check out this picure I got with todays date! Download the app: http://www.google.com");
sharingIntent.setType("image/jpg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(sharingIntent, "Share via"));

Here is an error I got from the logs, but I am not using an ArrayList to share.

W/Bundle: Key android.intent.extra.STREAM expected ArrayList but value was a android.net.Uri$StringUri.  The default value <null> was returned.

And what the Log.d prints out:

D/Sharing: android.resource://com.trommelen.okke.scheurkalender/drawable/image155
Okke Trommelen
  • 165
  • 1
  • 3
  • 12

1 Answers1

3

I have solved this problem by adding a bitmap and add the permission android.permission.WRITE_EXTERNAL_STORAGE to the Manifest

Bitmap imgBitmap=BitmapFactory.decodeResources(getResources(),R.drawable.image1);
String imgBitmapPath=Images.Media.insertImage(getContentResolver(),imgBitmap,"title",null);
Uri imgBitmapUri=Uri.parse(imgBitmapPath);

then add the imgBitmapUri as extra stream.

m33th
  • 76
  • 5