In my app, I show a list of posts where posts may have image. When user clicks on the post image, the create chooser shows available options like “photo”, “gallery”. My question is,why can't gallery open the image on android 7.0 or API 24 and above? I get an error “can not open file.” On API level 23 and below, I provide actual file path which seems to be working fine. I confirmed following things before posting this question.Interesting part is "Photo" could open it.
I get the proper content uri using FileProvider. My uri looks like this:
content://package.fileprovider/attachment/filename
I am using the proper mime type.
I am using proper intent and permission flags.Please see the below code:
Intent myIntent = new Intent(Intent.ACTION_VIEW); myIntent.putExtra(ShareCompat.EXTRA_CALLING_PACKAGE, getActivity().getPackageName()); myIntent.putExtra(ShareCompat.EXTRA_CALLING_ACTIVITY, getActivity().getComponentName());
myIntent.setDataAndType(uri, mimeType); myIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(myIntent, "Open file:"));