PermissionTracker

class PermissionTracker(activity: ComponentActivity, permissions: Map<String, Int>)

An object that tracks granted permissions and obtains required ones as needed.

The permission model used by this class is very simple: all potentially needed permissions must be listed upfront. A subset of permissions required for the functionality of a particular "target" screen is checked when attempting to show that screen. If all permissions required by the target screen are granted, it is shown normally. Otherwise a missing permission screen is shown with prompts to grant permission. When user grants permissions, view is changed to show the target screen automatically.

To use this functionality, create this object when activity is created. Call updatePermissions in ComponentActivity.onCreate. Then simply wrap the UI of any target screen in PermissionCheck call.

Parameters

activity

activity that hosts this object

permissions

a map from permission string to the text shown to the user to explain why that permission is necessary for this app

Constructors

Link copied to clipboard
constructor(activity: ComponentActivity, permissions: Map<String, Int>)

Functions

Link copied to clipboard

Check if the given set of permissions is granted.

Link copied to clipboard
fun PermissionCheck(permissions: Iterable<String>, displayPermissionRequest: Boolean = true, content: @Composable () -> Unit)

Ensure that the given set of permissions is granted and show the given content.

Link copied to clipboard
fun PermissionRequests(permissions: Iterable<String>, extraButtons: @Composable RowScope.() -> Unit = {})
Link copied to clipboard

Reads all the permission states (granted or not) from the system.