In my app I have internal files that I would like to be able to open in external viewers depending on file type. I have a FileProvider set up like the following in the application manifest:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.myapp.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/paths" />
</provider>
I user the following code to show an application selector in order to view the file.
Uri contentUri = getUriForFile(getApplicationContext(), "com.myapp.fileprovider", thisFile);
Intent viewIntent = new Intent(Intent.ACTION_VIEW);
String mimeType = getApplicationContext().getContentResolver().getType(contentUri);
viewIntent.setDataAndType(contentUri, mimeType);
viewIntent.setFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivity(viewIntent);
} catch(ActivityNotFoundException e) {}
This works well for most apps, however if I chose Google+ Photos app in the list, while the image will load fine in the Google+ Photos, it will crash immediately if I try too zoom in to the image by pinching with my fingers. It seem like Google+ Photos lost access to the file and when it tries to read it again it gets denied access.
All other apps I tried works perfectly Any suggestions appreciated