-
Notifications
You must be signed in to change notification settings - Fork 114
Open
Description
I was thinking on a variation of PermissionsManager.hasAllPermissions that only takes a context and retrieves all the app permissions out of the package info, just like PermissionsManager.requestAllManifestPermissionsIfNecessary
Just by looking at the code, it could be something like the following
public static boolean hasAllPermissions( @Nullable Context context ) {
if (context == null) {
return false;
}
PackageInfo packageInfo = null;
try {
Log.d(TAG, context.getPackageName());
packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "A problem occurred when retrieving permissions", e);
}
boolean hasAllPermissions = false;
if (packageInfo != null) {
hasAllPermissions = true;
String[] permissions = packageInfo.requestedPermissions;
if (permissions != null) {
for (String perm : permissions) {
hasAllPermissions &= ActivityCompat.checkSelfPermission(context, perm)
== PackageManager.PERMISSION_GRANTED;
}
}
}
return hasAllPermissions;
}Disclaimer: I have not tested the code nor even compiled it, this is just an idea. I will be happy to contribute properly if the idea is good enough.
Thanks
shishoufengwise1234
Metadata
Metadata
Assignees
Labels
No labels