Skip to content

Latest commit

 

History

History
79 lines (54 loc) · 3.1 KB

README.md

File metadata and controls

79 lines (54 loc) · 3.1 KB

permission_handler_ohos

pub package GitHub stars GitHub forks GitHub license GitHub issues harmony-candies

The plugin to request and check permissions on OpenHarmony.

权限列表来自: https://gitee.com/openharmony/docs/blob/OpenHarmony-4.1-Release/zh-cn/application-dev/security/AccessToken/permissions-for-all.md

注意

由于 OpenHarmonyHarmonyOS 的权限差异以及鸿蒙版本的高速迭代,检查请求权限的 api 是传递的权限的字符串全称,如果你发现 PermissionOhos 枚举中没有某个权限,你可以直接传递权限的字符串全称。等鸿蒙版本稳定下来了,会再同步权限列表到枚举中。

使用

dependencies:
  permission_handler_ohos: any

请认真阅读官方关于权限的文档 https://gitee.com/openharmony/docs/blob/OpenHarmony-4.1-Beta1/zh-cn/application-dev/security/AccessToken/app-permission-mgmt-overview.md#%E5%BA%94%E7%94%A8%E6%9D%83%E9%99%90%E7%AE%A1%E6%8E%A7%E6%A6%82%E8%BF%B0

在你的项目的 module.json5 文件中增加对应需要权限设置。

    requestPermissions: [
      { name: "ohos.permission.READ_CALENDAR" },
      { name: "ohos.permission.WRITE_CALENDAR" },
    ],

例子

检查权限状态

import 'package:device_info_plus_ohos/device_info_plus_ohos.dart';
 
    final PermissionStatusOhos status =
        await PermissionHandlerOhos.checkPermissionStatus(
            PermissionOhos.read_calendar.name);      

请求单个权限

    final PermissionStatusOhos status =
        await PermissionHandlerOhos.requestPermission(
      PermissionOhos.read_calendar.name,
    );

请求多个权限

    final Map<String, PermissionStatusOhos> statusMap =
        await PermissionHandlerOhos.requestPermissions([
      PermissionOhos.read_calendar.name,
      PermissionOhos.write_calendar.name,
    ]);

打开设置页面

   PermissionHandlerOhos.openAppSettings();