动态权限检查

1. 简介

动态权限检查,支持链式调用。

1.1. 特性

  1. 适配Android 8.0权限分组
  2. 支持检查APP通知权限
  3. 支持Android8.0安装未知来源应用权限检查

2. 基础环境

  • AndroidStudio 3.4.+
  • java1.8
  • gradle 5.1.1

3. 如何使用

3.1. Release版本

  • 项目依赖
allprojects {
  repositories {
        maven {
               // 配置用户名和密码
               credentials {
                   username 'anonymous'
                   password ''
               }
               // 配置仓库地址
               url 'http://172.16.28.234:8083/repository/maven-releases/'
           }
  }
}
  • 添加依赖

android-support版本

    implementation 'com.jpxx.android.library:rx-permissions-support:latest.integration'

3.2. 快照版本

  • 项目依赖
allprojects {
  repositories {
        maven {
               // 配置用户名和密码
               credentials {
                   username 'anonymous'
                   password ''
               }
               // 配置仓库地址
               url 'http://172.16.28.234:8083/repository/maven-snapshots/'
           }
  }
}
  • 添加依赖

android-support版本

    implementation 'com.jpxx.android.library:rx-permissions-support:1.0.0-SNAPSHOT'

4. 使用说明

4.1. 任意权限名称

new RuntimePermissionUtil(mRootView.getActivity())
                .requestSinglePermission(permissionName, explanationMessage, new RuntimePermissionUtil.RequestPermission() {
                    @Override
                    public void onRequestPermissionSuccess() {
                        // 允许
                    }

                    @Override
                    public void onRequestPermissionFailure(String permissionName) {
                        // 用户拒绝, APP会尝试弹出提示框,说明为什么需要此权限。说明文字是explanationMessage。
                    }

                    @Override
                    public void onRequestPermissionFailureWithAskNeverAgain(String permissionName) {
                        //用户彻底拒绝APP获取权限,开发者需要提醒用户去设置-应用里手动开启该权限。
                    }
                });

4.2. 内置的快速请求权限

  1. 请求通知权限

    new RuntimePermissionUtil(mRootView.getActivity())
                   .appNotification("xxxx", new RuntimePermissionUtil.RequestPermission() {
                       @Override
                       public void onRequestPermissionSuccess() {
                       }
    
                       @Override
                       public void onRequestPermissionFailure(String permissionName) {
    
                       }
    
                       @Override
                       public void onRequestPermissionFailureWithAskNeverAgain(String permissionName) {
    
                       }
                   });
    
  2. 请求获取手机状态的权限

    new RuntimePermissionUtil(mRootView.getActivity())
               .readPhonestate("xxxx", new RuntimePermissionUtil.RequestPermission() {
                   @Override
                   public void onRequestPermissionSuccess() {
                   }
    
                   @Override
                   public void onRequestPermissionFailure(String permissionName) {
    
                   }
    
                   @Override
                   public void onRequestPermissionFailureWithAskNeverAgain(String permissionName) {
    
                   }
               });
    
  3. 请求打电话权限

    new RuntimePermissionUtil(mRootView.getActivity())
               .callPhone("xxxx", new RuntimePermissionUtil.RequestPermission() {
                   @Override
                   public void onRequestPermissionSuccess() {
                   }
    
                   @Override
                   public void onRequestPermissionFailure(String permissionName) {
    
                   }
    
                   @Override
                   public void onRequestPermissionFailureWithAskNeverAgain(String permissionName) {
    
                   }
               });
    
  4. 请求发送短信权限

    new RuntimePermissionUtil(mRootView.getActivity())
               .sendSms("xxxx", new RuntimePermissionUtil.RequestPermission() {
                   @Override
                   public void onRequestPermissionSuccess() {
                   }
    
                   @Override
                   public void onRequestPermissionFailure(String permissionName) {
    
                   }
    
                   @Override
                   public void onRequestPermissionFailureWithAskNeverAgain(String permissionName) {
    
                   }
               });
    
  5. 请求外部存储的权限

    new RuntimePermissionUtil(mRootView.getActivity())
               .externalStorage("xxxx", new RuntimePermissionUtil.RequestPermission() {
                   @Override
                   public void onRequestPermissionSuccess() {
                   }
    
                   @Override
                   public void onRequestPermissionFailure(String permissionName) {
    
                   }
    
                   @Override
                   public void onRequestPermissionFailureWithAskNeverAgain(String permissionName) {
    
                   }
               });
    
  6. 请求摄像头权限

    new RuntimePermissionUtil(mRootView.getActivity())
                .launchCamera("xxxx", new RuntimePermissionUtil.RequestPermission() {
                    @Override
                    public void onRequestPermissionSuccess() {
                    }
    
                    @Override
                    public void onRequestPermissionFailure(String permissionName) {
    
                    }
    
                    @Override
                    public void onRequestPermissionFailureWithAskNeverAgain(String permissionName) {
    
                    }
                });
    

源码地址:http://172.16.28.234:8081/dev-plat/android/lib/rx-permissions

源码地址:http://sources.jpsycn.com/dev-plat/android/lib/rx-permissions.git

Copyright © jpsycn.com 2018 all right reserved,powered by Gitbook该文件修订时间: 2019-09-10 14:26:31

results matching ""

    No results matching ""