Android marshmallow request permission?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Until the release of Android 6.0 Marshmallow, controlling app permissions in Android was an all-or-nothing affair. Users were required to grant a potentially broad set of permissions to an app before installation, and those permissions remained in effect indefinitely unless the app was uninstalled. With the introduction of Android Marshmallow, Google revolutionized the way permissions are handled, adopting a more granular and flexible system which enhances user privacy and security.
New Permission Model in Android Marshmallow
Runtime Permissions
In Android Marshmallow, certain app permissions are requested at runtime instead of during installation. This means that users are prompted to grant or deny permissions as an app attempts to use a feature that requires them. This approach allows users to understand the context in which permissions are requested, giving them more control over their privacy.
Permission Groups
Permissions are now categorized into groups. If a user grants permission from a specific group, other permissions within that group may also be granted. For example, if an app requests access to the camera, it will automatically gain access to the microphone as well, since both permissions fall under the "camera" permission group.
Backward Compatibility
Apps built for Android 5.1 or lower aren't affected by the change and are treated with the old permission model on Android Marshmallow devices. But developers need to update their apps targeting API level 23 (Android 6.0) to take advantage of the new runtime permissions.
Implementing Runtime Permissions
Checking for Permission
Before accessing a feature that requires permission, developers should check whether it has already been granted. This can be done using the `ContextCompat.checkSelfPermission()` method:
- Explain Why: Clearly explain why a given permission is needed when requesting it, making it easier for the user to understand the necessity.
- Handle Graceful Degradation: Be prepared to thoughtfully handle cases where permissions are denied. Offer alternatives or gracefully degrade functionality.
- Minimize Permission Use: Request as few permissions as possible. Unnecessary or invasive permissions might lead to users declining your app or uninstalling it.

