简体   繁体   中英

Image doesn't get recognized

I have the following code:

FileOutputStream out = null;

try {
out = new FileOutputStream("/sdcard/tmp/i.jpg");
b.compress(Bitmap.CompressFormat.JPEG, 90, out);
Toast.makeText(getApplicationContext(), "Succeded", Toast.LENGTH_LONG).show();
} catch (Exception e) {
 Toast.makeText(getApplicationContext(), "Failed", Toast.LENGTH_LONG).show();
}

Intent share = new Intent(Intent.ACTION_SEND);

share.setType("image/jpeg");    

share.putExtra(Intent.EXTRA_STREAM, Uri.parse("/sdcard/tmp/i.jpg"));

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

When it is called it all works correctly. The file is saved and it pops up the chooser. but once you get to the activity you choose, they all pop up a message saying that I can't add that image. Except GMail, it works fine. So what on earth do I do to fix this?

I don't see any code to close the FileOutputStream . Maybe this is the issue reason? Try to call out.close() after you save the image.

UPDATE:

Also try to use full image path, ie try doing smth like this:

share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/tmp/i.jpg"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM