Android - File Provider - Permission Denial

Permission Denial while sharing file with FileProvider

Sorry about the late response. I solved it like this:

Intent chooser = Intent.createChooser(intentShareFile, "Share File");

List<ResolveInfo> resInfoList = this.getPackageManager().queryIntentActivities(chooser, PackageManager.MATCH_DEFAULT_ONLY);

for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
this.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}

startActivity(chooser);

This helped me: Permission Denial with File Provider through intent

Android 10 - file provider - permission denial: reading android.support.v4.content.FileProvider uri

I finally worked it out. Tunes out my URI construction has some problems. I changed it to

Context context = getApplicationContext();
File filelocation = new File(getFilesDir(), fileName);
Uri path = FileProvider.getUriForFile(context, "com.example.charleschung.mci_pa1", filelocation);

And it works. Hope it helps :)



Related Topics



Leave a reply



Submit