Open downloaded file on Android N using FileProvider
Thanks to @greenaps I was able to solve the issue. The local URI retrieved from the DownlodManager
was prefixed with file://
. This has to be dropped for the new FileProvider
:
if (localUri.substring(0, 7).matches("file://")) {
localUri = localUri.substring(7);
}
File file = new File(localUri);
here change in AndroidManifest.xml
<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/file_paths"/>
</provider>
change in file path
Uri contentUri;
if(Build.VERSION.SDK_INT == 24){
contentUri = FileProvider.getUriForFile(MainActivity.this,
getApplicationContext().getPackageName() + ".provider",
file);
} else{
contentUri = Uri.fromFile(file);
}