项目作者: TheSomeshKumar

项目描述 :
Android Library for Easily calling Runtime Permission on Android Marshmallow and above
高级语言: Kotlin
项目地址: git://github.com/TheSomeshKumar/PermissionMadeEasy.git
创建时间: 2017-12-24T11:39:29Z
项目社区:https://github.com/TheSomeshKumar/PermissionMadeEasy

开源协议:MIT License

下载


Android Arsenal
Release

Note: Deprecated as the new way of requesting permission is quite straightforward

PermissionMadeEasy

Android Library for Easily calling Runtime Permission on Android Marshmallow and above

How to build

Add Jitpack.io to your project level build.gradle file

  1. allprojects {
  2. repositories {
  3. maven { url 'https://jitpack.io' }
  4. }
  5. }

Add the dependency

  1. dependencies {
  2. implementation 'com.github.thesomeshkumar:permissionmadeeasy:1.2.3'
  3. }

How to use

Create a PermissionHelper object

  1. permissionHelper = PermissionHelper.Builder()
  2. .with(this)
  3. .requestCode(REQUEST_CODE_MULTIPLE)
  4. .setPermissionResultCallback(this)
  5. .askFor(Permission.CALENDAR, Permission.CAMERA, Permission.CONTACTS,
  6. Permission.LOCATION, Permission.MICROPHONE, Permission.STORAGE,
  7. Permission.PHONE, Permission.SMS, Permission.SENSORS)
  8. .rationalMessage("Permissions are required for app to work properly")
  9. .build()

and when you want to ask for the permission just call

  1. permissionHelper.requestPermissions()

Override onPermissionsGranted and onPermissionsDenied functions

Also override onRequestPermissionsResult and pass the arguments recieved to PermissionHelper class’ onRequestPermissionsResult function.

  1. @Override
  2. public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  3. super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  4. permissionHelper.onRequestPermissionsResult(requestCode, permissions, grantResults);
  5. }

Detailed full sample project is included. Check DemoActivity for full implemetation