6

In Android 6.0 (Marshmallow), users can revoke specific app permissions, even after granting it from inside the app. I know I can check permissions with ContextCompat.checkSelfPermission(). But Is there a way for my app to get notified when the user revokes one of my app's permissions, without repeated checking with ContextCompat.checkSelfPermission()? Maybe a broadcast/intent or something similar?

Thanks in advance for any help.

Mehedee
  • 73
  • 1
  • 7
  • http://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en – ecle Oct 28 '15 at 09:58
  • 1
    Unless the OEM implements a specific callback function of sort, as far as I know, this is not possible. – JavaChipMocha Dec 02 '15 at 18:31

1 Answers1

2

If your app needs a dangerous permission, you must check whether you have that permission every time you perform an operation that requires that permission. The user is always free to revoke the permission, so even if the app used a permission yesterday, it can't assume it still has that permission today.

To check if you have a permission, call the ContextCompat.checkSelfPermission() method. For example, this snippet shows how to check if the activity has permission to write to the calendar:

// Assume thisActivity is the current activity
int permissionCheck = ContextCompat.checkSelfPermission(thisActivity,
        Manifest.permission.WRITE_CALENDAR);

If the app has the permission, the method returns PackageManager.PERMISSION_GRANTED, and the app can proceed with the operation. If the app does not have the permission, the method returns PERMISSION_DENIED, and the app has to explicitly ask the user for permission.

Jithin Sunny
  • 3,352
  • 4
  • 26
  • 42
  • I know that I can check that in runtime. I wanted to know If there was a way to asynchronously know if user has revoked one of my permissions, without repeated checking with `checkSelfPermission()`. Maybe I was not clear enough in my question. Let me edit the original post. – Mehedee Oct 28 '15 at 05:40