鸿蒙开源组件——OHOS 权限库

发布于 2021-11-17 18:16
浏览
0收藏

 

EffortlessPermissions

简介

一个 OHOS 权限库,通过方便的添加扩展了 OHOS 权限。

功能

  • 动态权限申请
  • 用户拒绝权限弹框提示前往应用设置

演示

鸿蒙开源组件——OHOS 权限库-开源基础软件社区

集成

在project的build.gradle中添加mavenCentral()的引用

repositories {   
 	...   
 	mavenCentral()   
	 ...           
 }

在entry的build.gradle中添加依赖

dependencies { 
... 
implementation 'com.gitee.archermind-ti:effortlesspermissions:1.0.1' 
... 
}

使用说明

  • 申请权限
    @AfterPermissionGranted(REQUEST_CODE_SAVE_FILE_PERMISSION)
        private void saveFile() {
            if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_SAVE_FILE)) {
                // We've got the permission.
                saveFileWithPermission();
            } else {
                // Request the permissions.
                EffortlessPermissions.requestPermissions(this,
                        REQUEST_CODE_SAVE_FILE_PERMISSION, PERMISSIONS_SAVE_FILE);
            }
        }​
  • 权限拒绝处理
 @AfterPermissionDenied(REQUEST_CODE_SAVE_FILE_PERMISSION)
    private void onSaveFilePermissionDenied() {
        if (EffortlessPermissions.somePermissionDenied(this, PERMISSIONS_SAVE_FILE)) {
            // Some permission is permanently denied so we cannot request them normally.
            OpenAppDetailsDialogFragment.show(
                    "",
                    "App needs permission to save files. Please grant the \"Storage\" permission in system settings.", this);
        } else {
            // User denied at least some of the required permissions, report the error.
            ToastDialog dialog = new ToastDialog(this);
            dialog.setText("Save failed: Insufficient permissions");
            dialog.show();
        }
    }
  • 权限申请结果回调处理
@Override
    public void onRequestPermissionsFromUserResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsFromUserResult(requestCode, permissions, grantResults);
        EffortlessPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }

版本迭代

changelog

  • v1.0.2
  • v1.0.1
  • v1.0.0

编译说明

  1. 将项目通过git clone 至本地
  2. 使用DevEco Studio 打开该项目,然后等待Gradle 构建完成
  3. 点击Run运行即可(真机运行可能需要配置签名)

版权和许可信息

Copyright 2017 Zhang Hai

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.

effortless-permissions-master.zip 117.12K 0次下载
已于2021-11-17 18:16:52修改
收藏
回复
举报
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源 去关联
    相关推荐