Can I detect that a specific permission has been removed for my Android app?

Thus, with the advent of Android 4.3, it becomes possible to selectively disable certain permissions for applications .

This can cause problems when the application loses the resolution necessary for proper operation.

Does the system send a message when the permission is canceled, or how can I say that my application no longer has a specific permission? Ideally, I would like to inform the user that disabling permission A will result in the loss of xyz in the application.

+6
source share
1 answer

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

If you want to check all your permissions, you can 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; } 

If the input strings are permission names, for example, "android.permission.INTERNET" .

+2
source

Source: https://habr.com/ru/post/950805/


All Articles