-
Please do not try to put
exported="true"
as pointed out bypskink
, your app will crash the moment it loads. FileProvider is not meant to work in this state. -
Tried
intent.addFlags
solution byCommonsWare
. Not working. probably will only works withACTION_SEND
kind of intent. -
I found the answer in this post. Apparently the manual granting way is the only solution. But we can always loop thru the list of candidate packages and grantPermission to all of them.
List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); }