3

I need to share text+image via Facebook, email etc. Now, I use this code:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.settings_share_text));
//Uri path = Uri.parse("android.resource://com.android.mypackage/" + R.drawable.arrow);
Uri path = Uri.parse("android.resource://com.android.mypackage/drawable/arrow.png");
intent.putExtra(Intent.EXTRA_STREAM, path );
Intent mailer = Intent.createChooser(intent, null);
startActivity(mailer);

The problem is that when I use "arrow.png", it says "Couldn't show attachment" and doesn't attach image; when I remove .png, I cannot open attached file later. Basically, I need to attach png from drawable and some text and share it via ACTION_SEND

Roman
  • 2,079
  • 4
  • 35
  • 53

1 Answers1

3

Try to use

Uri.fromFile(new File("android.resource://com.android.mypackage/drawable/arrow.png"));

insted of

Uri.parse("android.resource://com.android.mypackage/drawable/arrow.png");

It will work fine if file descriptor will be valid.

Sergey Pekar
  • 8,555
  • 7
  • 47
  • 54