Can I detect that a particular permission has been removed for my android app?
Asked Answered
O

1

7

So with the arrival of Android 4.3 comes the ability to selectively disable particular permissions for apps.

This could obviously cause problems where an app loses a permission it needs to operate correctly.

Does the system broadcast a message when a permission is revoked, or how could I tell that my app no longer has a certain permission? Ideally I would like to inform the user that turning off permission A will break xyz in the application.

Overview answered 1/8, 2013 at 11:5 Comment(1)
It's been hidden for this reason, until they come up with a mechanism for developers to adjust for it.Procambium
D
3

There is no broadcast, but you can check permissions yourself on startup(or resume, etc). Context#checkCallingOrSelfPermission() is provided for this.

If you want to check all your permissions, you could do something like this:

public static boolean[] getPermissionsGranted(Context context, String[] permissions){
    boolean[] permissionsGranted = new boolean[permissions.length];
    for(int i=0;i<permissions.length;i++){
        int check = context.checkCallingOrSelfPermission(permissions[i]);
        permissionsGranted[i] = (check == PackageManager.PERMISSION_GRANTED);
    }
    return permissionsGranted;
}

Where the input Strings are the permissions' names, such as "android.permission.INTERNET".

Darell answered 1/8, 2013 at 12:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.