项目作者: Sorbh

项目描述 :
GetPermission is the easiest way to manage Android Marshmallow and Nougat runtime permissions.
高级语言: Java
项目地址: git://github.com/Sorbh/GetPermission.git
创建时间: 2018-04-29T17:43:21Z
项目社区:https://github.com/Sorbh/GetPermission

开源协议:

下载


GetPermission

GetPermission is the easiest way to manage Android Marshmallow and Nougat runtime permissions from activity or non-activity context.

open source
build number
version number
Size
Method count
License Apache

alt text

Motivation

Implementing runtime permissions forces the developer to add the code for granting (and checking if the permission has already been granted) in their Activities. At a time when everybody is trying to make their Activity classes lighter (with the help of Architecture Components by Google itself), this adds lots of boilerplate code in our activity.

So I intend to solve this by using a separate module which handles all the runtime permission hassle and implement runtime permission in less code and sync manner.

So this library handles all the permission handling logic.Even you can use it from non-activity context.

Getting started

Installing

To use this library simply import it by placing the following line under dependencies in your app module’s build.gradle file

This library is posted in jCenter

Gradle

  1. implementation 'in.unicodelabs.sorbh:getpermission:1.0.0'

Maven

  1. <dependency>
  2. <groupId>in.unicodelabs.sorbh</groupId>
  3. <artifactId>getpermission</artifactId>
  4. <version>1.0.0</version>
  5. <type>pom</type>
  6. </dependency>

Usage

if you want to ask single or multiple permission requests, you just need to create GetPermission builder, setPermission to it and enqueue the callback.
the same call back works for both single or multiple requests.

  1. new GetPermission.Builder(context).setPermissions(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.RECORD_AUDIO).enqueue(new PermissionResultCallback() {
  2. @Override
  3. public void onPermissionGranted(ArrayList<PermissionRequest> grantedPermission) {
  4. for (PermissionRequest permissionRequest : grantedPermission) {
  5. Log.d("Get Permission", "Granted - " + permissionRequest.getPermission());
  6. }
  7. }
  8. @Override
  9. public void onPermissionDenied(ArrayList<PermissionRequest> deniedPermission, final PermissionDeniedDelegate permissionDeniedDelegate) {
  10. for (final PermissionRequest permissionRequest : deniedPermission) {
  11. Log.d("Get Permission", "Denied - " + permissionRequest.getPermission());
  12. //Once user denied permission with never asked, show waring message to user and call this on
  13. //postive response to open the setting screen
  14. //if (permissionRequest.isPermanentlyDenied())
  15. // permissionDeniedDelegate.openSetting();
  16. }
  17. }
  18. @Override
  19. public void onPermissionRationalShouldShow(final ArrayList<PermissionRequest> rationalPermission, final PermissionRationalDelegate permissionRationalDelegate) {
  20. for (final PermissionRequest permissionRequest : rationalPermission) {
  21. Log.d("Get Permission", "Rational - " + permissionRequest.getPermission());
  22. //Call this on positive response on rational dialog
  23. //permissionRationalDelegate.requestPermission(permissionRequest, 110);
  24. }
  25. }
  26. });
  • Java permissionRationalDelegate.requestPermission(permissionRequest, 110) Show user Ration dialog on rational call back and on positive response call this method to ask permission again.
  • Java permissionDeniedDelegate.openSetting() in case user check the never asked and denied the permission, you can show user warning message and force the user to allow permission in setting by opening setting screen for the application.

Screenshots

alt text

Author

  • Saurabh K Sharma - GIT

    I am very new to open source community. All suggestion and improvement are most welcomed.

Contributing

  1. Fork it (https://github.com/sorbh/GetPermission/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

License

  1. Copyright 2018 Saurabh Kumar Sharma
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.