Created
September 7, 2018 13:05
-
-
Save fcaldarelli/9e591510cb02cf19fcdd249c3de40195 to your computer and use it in GitHub Desktop.
Uri file android target >= api 24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<paths xmlns:android="http://schemas.android.com/apk/res/android"> | |
<external-path name="external_files" path="."/> | |
</paths> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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