I have application with images and I want share image which is choosen by user in some other application. From other question here I know that I must put the image in public place so it can be accesed by other application. But I still get error "no application can perform this action" any idea where am I doing mistake? Code for copying image to SD card:
String path = Environment.getExternalStorageDirectory().toString();
File file = new File(path,String.valueOf(idOfImage));
if (!file.exists())
{
Bitmap myBitmap = BitmapFactory.decodeResource(getResources(),idOfImage);
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
myBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e)
{
e.printStackTrace();
} finally {
try {
if (out != null)
{
out.close();
}
} catch (IOException e)
{
e.printStackTrace();
}
}
Code for sending the intent and picking chooser:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
Uri uri = Uri.fromFile(file);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
StartActivity(Intent.createChooser(shareIntent,getResources().getText(R.string.share)));
Thanks for answers.
EDIT: Works fine when sharingIntent.setType("image/png"); lane added, with Gmail and G+ , but doesnt work with Messengers FB and others.