Skip to content

Instantly share code, notes, and snippets.

@swissonid
Created December 12, 2016 08:21
Show Gist options
  • Save swissonid/bb2961f91f2c75961cc820a77b13c17d to your computer and use it in GitHub Desktop.
Save swissonid/bb2961f91f2c75961cc820a77b13c17d to your computer and use it in GitHub Desktop.
Handle "file://" schema
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Context appContext = mWeakActivity.get().getApplicationContext();
return FileProvider.
getUriForFile(appContext, appContext.getPackageName() + ".provider", file);
}else {
return Uri.fromFile(file);
}
--------------------------------
Add to manifest
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment