Compose Permissions

Additional

Language
Kotlin
Version
N/A
Created
Aug 19, 2023
Updated
Aug 26, 2023
Owner
Jian James Astrero (jianastrero)
Contributor
Jian James Astrero (jianastrero)
1
Activity
Badge
Generate
Download
Source code

???? Compose Permissions

Streamline permission handling in Android Jetpack Compose applications with Compose Permissions.

A simple library to minimize boilerplate for implementing requesting and checking if permissions are granted or not.

Read more on Medium.

Overview

"Compose Permissions" is an Android library tailored to simplify the process of managing permissions within Jetpack Compose projects. Say goodbye to the verbosity of permission requests and checks, and welcome a cleaner, more efficient way to handle user permissions.

Demo

Installation

To integrate "Compose Permissions" into your project, just add the following dependency to your app's build.gradle file:

implementation("dev.jianastrero.compose-permissions:compose-permissions:1.1.0")

Usage

  1. Create a ComposePermission instance for the desired Android permission:
// Compose Permissions
val cameraPermission = composePermission(android.Manifest.permission.CAMERA)
  1. Request the permission using a concise line of code:
// Compose Permissions
cameraPermission.request()

Optionally, use the isGranted property to avoid unnecessary requests:

if (!cameraPermission.isGranted) {
    cameraPermission.request()
}

Example

val cameraPermission = composePermission(android.Manifest.permission.CAMERA)

if (!cameraPermission.isGranted) {
   cameraPermission.request()
}

Documentation

value

  • Description:
    • Returns a Map of String keys to PermissionStatus values.
    • Each key corresponds to a permission item, and the corresponding value represents the status of that permission.
  • Type: String
  • Example:
    • cameraPermission.value

isGranted

  • Description:
    • Determines whether all permission items have been granted.
    • Returns true if all permission items are granted, false otherwise.
  • Type: Boolean
  • Example:
    • cameraPermission.isGranted

shouldShowRationale

  • Description:
    • Indicates whether the rationale should be shown for all permission item.
    • Returns true if the rationale should be shown for all permission item, false otherwise.
  • Type: Boolean
  • Example:
    • cameraPermission.shouldShowRationale

request(vararg permissions: String)

  • Description:
    • Request permissions from the user.
    • permissions - The list of permissions to request from the user. Defaults to all permissions.
  • Type: Unit
  • Example:
    • cameraPermission.request()
    • cameraPermission.request(android.Manifest.permission.CAMERA)
get(vararg permissions: String)
  • Description:
    • Returns a Map of String keys to PermissionStatus values.
    • Each key corresponds to a permission item, and the corresponding value represents the status of that permission.
    • permissions - The list of permissions to get the status of. Defaults to all permissions.
    • Note: This is an operator function, so it can be called without the get keyword.
  • Type: Map<String, PermissionStatus>
  • Example:
    • cameraPermission.get()
    • cameraPermission.get(android.Manifest.permission.CAMERA)

value(vararg permissions: String)

  • Description:
    • Returns a Map of String keys to PermissionStatus values.
    • Each key corresponds to a permission item, and the corresponding value represents the status of that permission.
    • permissions - The list of permissions to get the status of. Defaults to all permissions.
  • Type: Map<String, PermissionStatus>
  • Example:
    • cameraPermission.value()
    • cameraPermission.value(android.Manifest.permission.CAMERA)

isGranted(vararg permissions: String)

  • Description:
    • Determines whether all permission items have been granted.
    • Returns true if all permission items are granted, false otherwise.
    • permissions - The list of permissions to check. Defaults to all permissions.
  • Type: Boolean
  • Example:
    • cameraPermission.isGranted()
    • cameraPermission.isGranted(android.Manifest.permission.CAMERA)

shouldShowRationale(vararg permissions: String)

  • Description:
    • Indicates whether the rationale should be shown for all permission item.
    • Returns true if the rationale should be shown for all permission item, false otherwise.
    • permissions - The list of permissions to check. Defaults to all permissions.
  • Type: Boolean
  • Example:
    • cameraPermission.shouldShowRationale()
    • cameraPermission.shouldShowRationale(android.Manifest.permission.CAMERA)

???? What's Next?

  • Add support for multiple permissions
  • Add support for iOS and other platforms (Kotlin Multiplatform)

✒️ Contributing

We value all forms of contributions from the community, including bug reports, issues, pull requests, documentation updates, and other improvements. Please respect our guidelines and community when making a contribution.

License

This project is licensed under the MIT License - see the LICENSE file for details