Search code examples
c#androidxamarinpermissionsxamarin.essentials

Is it recommended (or even possible) to remove permissions from an app on Android after they have been granted?


I am using Xamarin and Xamarin.Essentials, although this question probably applies to all Android development.

I have an application which asks the user for permission to read activity (steps) from the hardware. The user can either grant or deny permissions. If the user denies, then the application does not perform the usual step reporting logic.

A user may choose to grant steps permission, but I would like to allow the user to change their mind later. Is it possible for an app to request that its own permission which have been previously granted be revoked? This would simplify the coding as I could rely on the existing logic in my app rather than adding an extra layer for whether it has been revoked.

I looked through the Xamarin Essentials API and didn't see anything obvious about revoking permissions. Is this possible? Or is it recommended that an app direct the user to the Android settings to revoke permissions? If it is possible, can anyone point me to documentation (Xamarin would be great if possible) to accomplish this?


Solution

  • There are several cases that might apply to your situation:

    1. On Android 11+ (API 30+), your app can request one-time permissions.
    2. On Android 13+ (API 33+), your app can call revokeSelfPermissionOnKill() to proactively remove its access to a runtime permission.
    3. The user can manually revoke an app's permissions, Your app had better handle this gracefully.
    4. On Android 11+, the OS will automatically reset permissions of any app that hasn't been used in a few months.

    Do see the Android developer docs: