Android: Share the intention of the image not to work with Facebook?


Hi I have the following code to share an image:

// Share
Intent share = new Intent(Intent.ACTION_SEND);

Uri uri = Uri.parse(getFilesDir() + File.separator + "myGoal.jpg");
        share.putExtra(Intent.EXTRA_STREAM, uri);

startActivity(Intent.createChooser(share, "Share Image"));

It works to share the image to Dropbox but if I pick the Facebook option, I get Facebook's status update dialog with no image attached and if I try to update my status with 'Test' it doesn't work. No errors. Just not working.

I know it's not the image because it uploads to my Dropbox properly and I can pull up the image and look at it.

Do I have to attach the image to the intent differently for it to work with Facebook?

Any ideas? I'm debugging on a physical device.

So I figured out the problem.

I was saving the picture to internal storage with getFilesDir() which put the picture into my apps sandbox and made inaccessible to the other apps.

I replaced my code with the following:

String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() +

File dir = new File(file_path);
File file = new File(dir, "myPic.png");
FileOutputStream fOut = new FileOutputStream(file);

screenshot.compress(Bitmap.CompressFormat.PNG, 100, fOut);


// Share
Intent share = new Intent(Intent.ACTION_SEND);

share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
share.putExtra(Intent.EXTRA_TEXT, "My Image");

startActivity(Intent.createChooser(share, "Share Image"));

Works perfectly fine now.