From 5cd7693906c90a76f56272bb56e9711267668a11 Mon Sep 17 00:00:00 2001 From: Eason Date: Mon, 7 Jun 2021 17:20:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- build.gradle | 2 + entry/build.gradle | 2 + .../audiovisualizer/sample/BaseAbility.java | 65 ++++++++++--------- 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 0cbefa3..ab55dbf 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ - 功能:实现音频可视化 - 项目移植状态:主功能完成 - 调用差异:无 -- 开发版本:sdk5,DevEco Studio2.1 beta4 +- 开发版本:sdk5,DevEco Studio2.1 Release - 基线版本:Release v2.2.0 #### 效果演示 @@ -33,7 +33,7 @@ allprojects { } ``` -在sdk5,DevEco Studio2.1 beta4下项目可直接运行 +在sdk5,DevEco Studio2.1 Release下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 diff --git a/build.gradle b/build.gradle index 70a46e6..7d1cef8 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,7 @@ ohos { buildscript { repositories { + maven { url 'https://mirrors.huaweicloud.com/repository/maven/' } @@ -29,6 +30,7 @@ buildscript { allprojects { repositories { + mavenCentral() maven { url 'https://mirrors.huaweicloud.com/repository/maven/' } diff --git a/entry/build.gradle b/entry/build.gradle index e192d44..b0bc307 100644 --- a/entry/build.gradle +++ b/entry/build.gradle @@ -14,6 +14,8 @@ dependencies { testCompile 'junit:junit:4.12' compile project(path: ':audiovisualizer') ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' + implementation 'io.openharmony.tpc.thirdlib:XXPermissions:1.0.2' + } diff --git a/entry/src/main/java/com/chibde/audiovisualizer/sample/BaseAbility.java b/entry/src/main/java/com/chibde/audiovisualizer/sample/BaseAbility.java index 526834a..d10cd02 100644 --- a/entry/src/main/java/com/chibde/audiovisualizer/sample/BaseAbility.java +++ b/entry/src/main/java/com/chibde/audiovisualizer/sample/BaseAbility.java @@ -15,18 +15,19 @@ */ package com.chibde.audiovisualizer.sample; + import com.chibde.audiovisualizer.util.PlaySoundUtil; -import com.chibde.visualizer.ResourceTable; +import com.hjq.permissions.OnPermission; +import com.hjq.permissions.XXPermissions; + import ohos.aafwk.ability.Ability; -import ohos.aafwk.ability.AbilitySlice; import ohos.aafwk.content.Intent; -import ohos.agp.components.Image; import ohos.agp.utils.Color; import ohos.agp.window.dialog.ToastDialog; import ohos.agp.window.service.WindowManager; -import ohos.bundle.IBundleManager; import java.io.IOException; +import java.util.List; /** * BaseAbility that contains common code for all visualizers @@ -53,23 +54,34 @@ abstract public class BaseAbility extends Ability { } private void getPermissions() { - if (verifySelfPermission("ohos.permission.MICROPHONE") != IBundleManager.PERMISSION_GRANTED) { - // 应用未被授予权限 - if (canRequestPermission("ohos.permission.MICROPHONE")) { - // 是否可以申请弹框授权(首次申请或者用户未选择禁止且不再提示) - requestPermissionsFromUser( - new String[]{"ohos.permission.MICROPHONE"}, 23); - - } else { - // 显示应用需要权限的理由,提示用户进入设置授权 - - } - - } else { - // 权限已被授予 - //初始化的方法 - initialize(); - } + XXPermissions.with(BaseAbility.this) + .permission("ohos.permission.MICROPHONE") + .request(new OnPermission() { + @Override + public void hasPermission(List list, boolean b) { + if (b) { + + initialize(); + } else { + terminateAbility(); + } + } + + @Override + public void noPermission(List list, boolean b) { + if (b) { + //toast("被永久拒绝授权,请手动授予拍照权限"); + // 如果是被永久拒绝就跳转到应用权限系统设置页面 + String[] permissions = new String[list.size()]; + list.toArray(permissions); + XXPermissions.startPermissionActivity(BaseAbility.this, permissions, this); + } else { + //toast("获取拍照权限失败"); + new ToastDialog(getContext()).setText("获取权限失败").show(); + terminateAbility(); + } + } + }); } private void initialize() { @@ -89,17 +101,6 @@ abstract public class BaseAbility extends Ability { init(); } - @Override - public void onRequestPermissionsFromUserResult(int requestCode, String[] permissions, int[] grantResults) { - super.onRequestPermissionsFromUserResult(requestCode, permissions, grantResults); - if (requestCode == 23) { - - initialize(); - } else { - terminateAbility(); - - } - } @Override protected void onStop() { -- Gitee