Skip to content

Instantly share code, notes, and snippets.

@fcaldarelli
Created September 7, 2018 13:05
Show Gist options
  • Save fcaldarelli/9e591510cb02cf19fcdd249c3de40195 to your computer and use it in GitHub Desktop.
Save fcaldarelli/9e591510cb02cf19fcdd249c3de40195 to your computer and use it in GitHub Desktop.
Uri file android target >= api 24
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
<!-- FILE PROVIDER PATHS -->
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mypackage.mobile.file_provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
if(file!=null)
{
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri fileUri = FileProvider.getUriForFile(getActivity(), getActivity().getApplicationContext().getPackageName() + ".file_provider", file);
intent.setDataAndType( fileUri, "image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment