Android M Permissions Confused on the usage of shouldShowRequestPermissionRationale function
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Android M, also known as Android 6.0 Marshmallow, introduced significant changes in the app permission model, shifting from installation-time permissions to runtime permissions. One of the key features of this change is the ability for users to review and revoke app permissions at runtime. This article will explore the concept of runtime permissions, focusing on the `shouldShowRequestPermissionRationale()` function, a commonly misunderstood component.
Understanding Android M Permissions
Runtime Permissions Overview
In Android Marshmallow and onwards, permissions are requested at runtime rather than when the app is installed. This means:
- Apps need to request permission to access certain features at the time they are needed.
- Users can grant or deny access, providing more control over app permissions.
- Permissions can be changed in the app's settings.
Role of `shouldShowRequestPermissionRationale()`
The method `shouldShowRequestPermissionRationale()` is a crucial part of the runtime permission model. It provides a way to enhance user experience by explaining the need for certain permissions. Here's what you need to know:
- Purpose: This method returns `true` if the app should show a rationale for requesting a permission. It returns `false` if the user has denied the permission in the past and selected "Don't ask again" or if the permission request is yet to be made.
- Usage: It's meant to be used before requesting a permission to provide context. For example, if a user denied a permission previously, your app could choose to display an explanation dialog before asking for the permission again.
Here’s an example to illustrate its practical application:
- First Permission Request: Initially, this method returns `false` because the user hasn't denied the permission yet.
- Subsequent Requests: If the user denies the permission once, this method will return `true` on subsequent requests, giving you a chance to explain before re-requesting.
- Check for "Don't ask again": The method returns `false` if the user selects "Don't ask again" after denying the permission. In this scenario, the rationale workflow should be skipped.
- Internet Access
- Vibration
- Wake Lock
- `requestPermissions()`: Request app permissions from the user.
- `onRequestPermissionsResult()`: Handle the result of the permission request.
- `checkSelfPermission()`: Check the status of a given permission.
Related reading
- Anything wrong with NOT signing a .NET assembly?
- Apache Beam pipeline running on Dataflow failed to read from KafkaIO SSL handshake failed
- Apache Ignite Spring secutiry error
- Apache kafka 2.0.0 version - Connection to node 1 failed authentication due to SSL handshake
- Android M Permissions onRequestPermissionsResult() not being called
- Android M Permissions onRequestPermissionsResult not being called
- Apache kafka consumer java.security.cert.CertificateException No subject alternative names present
- Apache Kafka doens't start after SSL configuration

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.