• Stars
    star
    109
  • Rank 307,915 (Top 7 %)
  • Language
    Kotlin
  • Created over 3 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A clean approach to deal with Permissions in Android

This small project shows a clean and simplified approach for the recommended workflow for requesting permissions in Android.

Dependencies

You need to use AndroidX Fragment 1.3.0 or higher.

implementation "androidx.fragment:fragment-ktx:1.3.0-rc01"

How to use

Using it is as simple as registering the PermissionManager with your Fragment and, whenever you want to request permissions, you just have to send what permissions you need, a rationale of why you're requesting those permissions for a second time, and then simply get the results as a callback:

class YourFragment : Fragment() {

    private val permissionManager = PermissionManager.from(this)
    yourView.setOnClickListener {
        permissionManager
            .request(Permission.Camera)
            .rationale("We need permission to use the camera")
            .checkPermission { granted: Boolean ->
                if (granted) {
                    // Do something with the camera
                } else {
                    // You can't access the camera
                }
            }
    }
}

Requesting multiple permissions simultaneously

Option 1: Simply add a new entry to the Permission class with your required permissions:

sealed class Permission(vararg val permissions: String) {
    // Individual permissions
    object Camera : Permission(CAMERA)

    // Bundled permissions for MyFeature
    object MyFeature : Permission(CAMERA, WRITE_EXTERNAL_STORAGE)
}

Option 2: Send as many Permission as you require to the PermissionManager:

permissionManager.request(Permission.Camera, Permission.Storage, Permission.Location)

Checking permission results individually

checkPermission { } will return a Boolean telling you whether all permissions were granted or not. If you want more granular control about which permissions were granted or declined, you can use checkDetailedPermission { } to receive a Map<Permission, Boolean> with the results:

permissionManager
    .request(Permission.Camera, Permission.Storage)
    .rationale("We need two permissions at once!")
    .checkDetailedPermission { result: Map<Permission, Boolean> ->
        if (result.all { it.value }) {
            // We have all the permissions
        } else {
            // Check in result which permission was denied
        }
    }

More Repositories

1

android-proxy-toggle

Small application to help android developers to quickly enable and disable proxy settings
Kotlin
260
star
2

ConfigGenerator

Configuration file code generator for use in Xcode projects
Swift
157
star
3

TABTestKit

Library designed to make writing and maintaining automated tests for iOS applications. This includes automation of bio-metrics and controlling of mock servers
Swift
54
star
4

accessibility-guidelines

Plain language summary of the Web Content Accessibility Guidelines
HTML
47
star
5

MasterFastfile

Master Fastfile used for internal builds
Ruby
34
star
6

TABResourceLoader

Framework for loading resources from a network service
Swift
29
star
7

TABSwiftLayout

Provides a flexible, yet minimal API for dealing with AutoLayout programatically
Swift
14
star
8

kc-android

KC Android App
Java
12
star
9

where-to-learn-about-accessibility

Here are some of the best resources to start learning about accessibility and inclusive design.
10
star
10

engineering-challenge

Coding challenge for engineers interested in joining our passionate team
Swift
7
star
11

TABScrollingContentView

A scroll view whose content size is determined based on the auto layout constraints of its subviews.
Swift
6
star
12

engineering-reading-list

A collection of podcasts, publications, tutorials, blogs and industry leaders recommended by the Kin + Carta Engineering CoP (Community of Practice).
5
star
13

TABCommunicate

Lightweight strongly typed wrapper around Multipeer Connectivity
Swift
5
star
14

Android-Code-Guidelines

3
star
15

ARKit-Glasses

Swift
2
star
16

github-actions-demo

Github Actions Demo for Android COP
Kotlin
1
star
17

iOS-Style-Guide

Our coding style guide for Objective C and Swift
1
star
18

kap-shopping-app

kap shopping app
TypeScript
1
star
19

ios-challenge

[OLD] Coding challenge for iOS engineers looking to join our passionate team
1
star
20

patios

Manage large Open API specifications and automatically generate TypeScript definitions from them.
TypeScript
1
star
21

Tracy

An example of how to create a simple Contact Tracing app for iOS and Android using Bluetooth LE
Kotlin
1
star
22

chef-zypper

Ruby
1
star
23

ModularSlothCreator

Modular Sloth Creator project for DocC and Danger Blog Posts on https://medium.com/kinandcartacreated/
Swift
1
star
24

chef-rvm

Chef cookbook for RVM. Recipes for installing system wide and by user. LWRPs to manage Rubies, gems, gemsets, wrappers.
Ruby
1
star