How to Request Android Runtime Permissions using Jetpack Compose?
A simple app example and proper way to request Android runtime permission workflow using Accompanist Permissions library for Jetpack Compose
There are 2 types of permissions:
- Install-time permissions
- Runtime permissions
An example of the most common install-time permissions is internet permissions. The Android OS system automatically grants your app the permission when the app is installed. You just need to declare the permission in the AndroidManifest.xml.
Unlike runtime permissions, in addition to declaring the permissions in the AndroidManifest.xml, you also need to manually request the permissions in your app. There are some gotchas on requesting runtime permissions, which will be discussed later.
Why Accompanist Permissions?
After playing around with different Android permission implementations in Jetpack Compose, I prefer to use Accompanist permissions library over rememberLauncherForActivityResult()
for the following reasons:
- Permissions state checking is slightly easier using
rememberPermissionState()
orrememberMultiplePermissionsState()
…