0

I'm trying to share an image through an shareActionProvider, but every App I try to share the file with, seem not to take care of the file: the selected app will be open, but after that I don't see any image (i.e. skype opens itself but does not send any file at all)

Here is what I put in my onCreateOptionsMenu:

getSupportMenuInflater().inflate(R.menu.menu_statistics, menu);

ShareActionProvider mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.actionbar_share_chart).getActionProvider();

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");

String root= Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/charts");
String fname = "chart.png";
File file = new File(myDir, fname);
URI uri = file.toURI();
shareIntent.putExtra(Intent.EXTRA_STREAM, uri.toString());
mShareActionProvider.setShareIntent(shareIntent);

if(file.exists())
    Log.d("debugCheck", "the file exists");

return true;

what I obtain is of course a

the file exists

in my logs. So, why is that? Why the app will be open but no images will be attached?

Bertuz
  • 2,390
  • 3
  • 25
  • 50

1 Answers1

0

Ok, I've found the error. Instead of using that URI class I should have created an Uri object:

Uri screenshotUri = Uri.parse("file:///storage/sdcard0/charts/chart.png");

And I should have passed it as an extra to the Intent

shareIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);

Case solved!

Bertuz
  • 2,390
  • 3
  • 25
  • 50