简体   繁体   中英

Handling permissions when we disable (revoke) them from app settings

We have an app with some permissions granted. Then an user revokes the permissions from Settings -> App -> Permissions. I mention that the app is in background in this time.

Sometimes, the app crashes when the above flow is happening. Is there any way to handle this ? Can we know when the permission is revoked from app settings ?

I did not find any official documentation related to this subject.

The scenario:

  1. Open app and give all the permissions.
  2. Click Home button (app in background).
  3. Manually revoke the permissions from Settings.
  4. Go back to the app -> it crashes

Thank you.

There is no such thing documented about receiving an event when your runtime permission is revoked which is granted by the user previously, So the Broadcast receiver won't help here.

Further, if permission is revoked by the user, you process will be terminated which was dependent to that critical permission.

If the above case fails, you can check with checkSelfPermission() call. In fact checking permission before performing any critical action is a good practice as well

Go back to the app -> it crashes

Never happened to me. Or may be I didn't tried ;-) The dependent process must be killed somehow so that you can check when code is called next time. If you are working with activity or fragment you should go for onResume() , where you can check permission using checkSelfPermission() .

Got reference from One of the SO link

You should check whether the permission is granted or not, and handle it as per your requirement:

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    switch (requestCode) {
        case //location_permission_code:
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            } else {

            }
        break;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM