5 Star 3 Fork 0

Archermind-TI/EffortlessPermissions_ohos

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 2.99 KB
一键复制 编辑 原始数据 按行查看 历史
杭迎秋 提交于 2021-09-29 06:49 . 更新文档

EffortlessPermissions

简介

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

功能

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

演示

image

集成

在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.
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/archermind-ti/effortless-permissions.git
git@gitee.com:archermind-ti/effortless-permissions.git
archermind-ti
effortless-permissions
EffortlessPermissions_ohos
master

搜索帮助

Cb406eda 1850385 E526c682 1850385