Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overload hasAllPermissions #11

Open
robertoestivill opened this issue Dec 3, 2015 · 0 comments
Open

Overload hasAllPermissions #11

robertoestivill opened this issue Dec 3, 2015 · 0 comments

Comments

@robertoestivill
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant