Created
February 15, 2018 23:38
-
-
Save k3170makan/c89849ff0be2fe3e142c82845cb20bf9 to your computer and use it in GitHub Desktop.
Code granting permissions based on app names
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
| public static void grantAppPermission(Context context, Intent intent, Uri fileUri) { | |
| List<ResolveInfo> resolvedIntentActivities = context.getPackageManager() | |
| .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); | |
| for (ResolveInfo resolvedIntentInfo : resolvedIntentActivities) { | |
| String packageName = resolvedIntentInfo.activityInfo.packageName; | |
| context.grantUriPermission(packageName, fileUri, | |
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment