• Stars
    star
    110
  • Rank 316,667 (Top 7 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated almost 3 years ago

Reviews

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

Repository Details

Android Permission lib PowerPermission makes handling runtime permissions extremely easy.

PowerPermission

Issues Pull Requests Code Size Contributors License Android Check CI

English Documentation | 中文文档

Table of Contents

Introducation

PowerPermission is a library to simplify process of demanding RuntimePermission.

You find an example application in this Repo or downloading directly here. Here are some different points compare with other libraries:

  • support asking permissions in AppCompatActivity and Fragment(include ChildFragment)
  • support custom rational view after user refuse permission
  • support ability to choose permissions to display rational views
  • support different interface (RxJava2,RxJava3,Coroutines,LiveData)

How to Download

Basic

implementation "com.qifan.powerpermission:powerpermission:1.5.0"

Other API Support

implementation "com.qifan.powerpermission:powerpermission-rxjava2:1.5.0"
implementation "com.qifan.powerpermission:powerpermission-rxjava3:1.5.0"
implementation "com.qifan.powerpermission:powerpermission-coroutines:1.5.0"
implementation "com.qifan.powerpermission:powerpermission-livedata:1.5.0"

OverView

Package Name Role Usage
powerpermission Basic core package implementation "com.qifan.powerpermission:powerpermission:1.5.0"
powerpermission-rxjava2 Support RxJava2 implementation "com.qifan.powerpermission:powerpermission-rxjava2:1.5.0"
powerpermission-rxjava3 Support RxJava3 implementation "com.qifan.powerpermission:powerpermission-rxjava3:1.5.0"
powerpermission-coroutines Support Kotlin Coroutine implementation "com.qifan.powerpermission:powerpermission-coroutines:1.5.0"
powerpermission-livedata Support Android LiveData implementation "com.qifan.powerpermission:powerpermission-livedata:1.5.0"

How to use

Simple Usage

Singleton

  PowerPermission.init()
            .requestPermissions(
                context = this@ExampleActivity,
                permissions = *arrayOf(
                    Manifest.permission.CAMERA
                )
            ) { permissionResult ->
                when {
                    permissionResult.hasAllGranted() -> {
                        doPermissionAllGrantedWork(permissionResult.granted())
                    }
                    permissionResult.hasRational() -> {
                        doPermissionReasonWork(permissionResult.rational())
                    }
                    permissionResult.hasPermanentDenied() -> {
                        doPermissionPermanentWork(permissionResult.permanentDenied())
                    }
                }
            }

Extension

  • Require in Activity
 askPermissions(
            Manifest.permission.CAMERA,
            Manifest.permission.READ_CALENDAR
        ) { permissionResult ->
            //do whatever you want
        }
  • Require in Fragment
 askPermissions(
            Manifest.permission.CAMERA,
            Manifest.permission.READ_CALENDAR
        ) { permissionResult ->
            //do whatever you want
        }
  • Require in ChildFragment
 askPermissions(
            Manifest.permission.CAMERA,
            Manifest.permission.READ_CALENDAR
        ) { permissionResult ->
            //do whatever you want
        }

RxJava/RxKotlin

Basic Usage

 simpleRequestButton.setOnClickListener {
            askPermissionsRx(Manifest.permission.CAMERA)
}

Use with RxBinding

 rxBindingRequestButton.clicks()
            .throttleFirst(1L, TimeUnit.SECONDS)
            .flatMap {
                askPermissionsRx(Manifest.permission.CAMERA)
            }

Coroutine

    simpleRequestButton.setOnClickListener {
            launch {
                val result = awaitAskPermissions(
                    Manifest.permission.CAMERA,
                    rationaleDelegate = dialogRationaleDelegate
                )
                //do something for this permission result
               // handlePermissionRequest(result)
            }
        }

Livedata

simpleRequestButton.setOnClickListener {
            observeAskPermissions(
                Manifest.permission.CAMERA,
                rationaleDelegate = dialogRationaleDelegate
            ).observe(this, Observer{ result->
               //do something for this permission result
               // handlePermissionRequest(result)
            })
        }

Rationale Interface

Custom View

In PowerPermission it have a interface which called RationaleDelegate, it should be used as bridge to create your proper
delegation class to implement this interface. It provide two basic public declaration functions,

  • displayRationale
//aims to display a view to explain reason to user why request permissions
    fun displayRationale(
        vararg permission: Permission,
        message: String,
        actionCallback: RationaleActionCallback
    )
  • onDismissView
//aims to simply disappear view and do some clean work etc.
 fun onDismissView()

PS: PowerPermission has already provided a class called DialogRationaleDelegate.kt to display a classic dialog view you can take a look at it and find more inspiration.

Choose those permissions are rational

  • RationaleData It's a data class used as choose which permission or permissions to display rationale view. And what kind of message will be displayed in your rational view. example:
RationaleData(
            rationalPermission = Manifest.permission.CAMERA,
            message = message
        )
RationaleData(
            rationalPermissions = listOf(Manifest.permission.CAMERA),
            message = message
        )

License

Copyright (C) 2020 Qifan Yang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

NFCAndroid

This is a project to using android HCE by using Type-4-Tag Message to working both in iOS and Android
Kotlin
205
star
2

RotateLabelView

This is library to help you to add a sticky rotation label into your view.
Kotlin
36
star
3

zeplin-asset-download-gradle

A simple gradle plugin that lets you create a download asset from zeplin and convert them to vector drawables automatically elephant project using 100% Kotlin and be up and running in a few seconds.
Kotlin
23
star
4

NFCReaderiOS

This is a project ios of read nfc tag
Swift
15
star
5

TimeLine

ExpandableListView做的android时间轴,child有左右滑动的效果并进行相关的操作(如:编辑、删除、置顶等)
Java
12
star
6

create-release-with-debugapk

This is a github workflow action to create a release with an additional apk as an attachment.
JavaScript
12
star
7

webrtcsamples

A collection of webrtc samples based on different platform(web,android,ios)
Kotlin
11
star
8

TypingIndicator

A lib will showing something like typing indicator.
Kotlin
7
star
9

EasyParking

mini project for parking
Java
4
star
10

RxJavaWithCleanArchiture

This is a practice project for using clean architecture with Dagger2.
Java
2
star
11

underwindfall

This is a repo used by kotlin gradle to update my github profile readme.
Kotlin
2
star
12

LifeCycleBehavior

Kotlin
1
star
13

FlutterGithubDashboard

This is a simple project by using Google Flutter.
Dart
1
star
14

iBeats

Python
1
star
15

Gank-Coroutines-MVVM

This is a simple project based on Kotlin Coroutines and Jetpack ViewModel
Kotlin
1
star
16

resume

My resume built by react
JavaScript
1
star
17

recognition-character-RBF-Opencv

mini project for recognizing character by using algorithm RBF
C++
1
star
18

RNScanCode

A ReactNative component to scan barcode.
Makefile
1
star
19

Algorithme

练习总结算法的地方
Java
1
star