npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cordova-ohos/cordova-plugin-android-permissions

v1.1.5

Published

Cordova android-permissions Plugin

Readme

cordova-plugin-android-permissions

专为 Android 平台设计的 Cordova 权限管理插件,专注于解决 Android 6.0(API 23)及以上版本的动态权限申请、权限状态检查与系统权限管理问题。提供简洁易用的 API 接口,覆盖 Android 系统所有危险权限的管理场景,帮助开发者快速实现合规的权限控制逻辑,保障应用在 Android 不同版本下的功能稳定性与安全性。

重要提示: 本插件主要是说明从Andorid移植到OHOS系统仍使用原Android接口,方便移植,无需修改接口。如果您是新项目,无需安装该插件,具体插件所需要的权限,已经在插件中申请,甚至您无需单独下载申请权限的插件。

核心特性

  1. 专注 Android 平台:深度适配 Android 动态权限机制,支持从 Android 6.0(API 23)到最新 Android 15 的全版本覆盖

  2. 完整权限管理能力:支持权限检查、单个 / 多个权限申请、权限状态监听、系统权限设置页跳转

  3. 危险权限全覆盖:包含 Android 系统定义的所有危险权限(如相机、存储、位置、麦克风等),无需额外扩展

  4. 原生级权限交互:遵循 Android 系统权限申请流程,支持权限申请结果回调、“不再询问” 状态识别

  5. 简洁 API 设计:采用直观的方法命名与参数结构,降低学习成本,5 分钟即可上手集成

  6. 错误处理机制:提供明确的错误码与描述,便于定位权限申请失败原因(如系统限制、用户拒绝等)

  7. TypeScript 支持:内置类型定义文件,支持 TypeScript 项目开发,提升代码可读性与稳定性

安装指南

1. 基础安装(推荐)

通过 npm 安装最新稳定版,适用于大多数 Cordova 项目:

# 安装hcordova
npm install -g hcordova

# 指定OHOS平台安装
hcordova plugin add cordova-plugin-android-permissions --platform ohos

2. 安装指定版本

如需兼容特定 Cordova 或 Android 版本,可指定插件版本号:

# 安装 1.0.0
hcordova plugin add [email protected] --platform ohos

3. 从 GitCode 安装开发版

如需测试最新功能或修复,可从 GitHub 仓库安装开发分支:

hcordova plugin add https://gitcode.com/OpenHarmony-Cordova/cordova-plugin-android-permissions.git --platform ohos

4. 卸载插件

# 全平台卸载
hcordova plugin remove cordova-plugin-android-permissions

# 指定OHOS平台卸载
hcordova plugin remove cordova-plugin-android-permissions --platform ohos

详细 API 文档

1. 核心常量

插件内置所有 OHOS 危险权限的常量,可直接通过 cordova.plugins.permissions.[常量名] 访问,推荐您直接使用OHOS权限字符串,原Android的权限常量已更换为常用的HamronyOS常量,在Android项目移植时,请检查您的权限名称。

OHOS权限参考连接 https://docs.openharmony.cn/pages/v6.0/zh-cn/application-dev/security/AccessToken/app-permission-mgmt-overview.md

2. 核心方法

2.1 检查权限状态

function checkPermission() {
    var permissions = [cordova.plugins.permissions.ACCESS_LOCATION_EXTRA_COMMANDS,cordova.plugins.permissions.ACCESS_COARSE_LOCATION];
    //直接使用鸿蒙权限名称
    //var permissions = ['ohos.permission.APPROXIMATELY_LOCATION','ohos.permission.LOCATION'];
    cordova.plugins.permissions.checkPermission(permissions, function(result){
        document.getElementById("checkPermissionInfo").innerHTML = JSON.stringify(result);
        if(result.hasPermission) {
          //具备权限
        }
    },function(){
    })
}

2.2 申请单个权限

function requestPermission() {
    var permissions = 'ohos.permission.APPROXIMATELY_LOCATION';
    cordova.plugins.permissions.requestPermission(permissions, function(result){
        document.getElementById("requestPermissionInfo").innerHTML = JSON.stringify(result);
        if(result.hasPermission) {
          //具备权限
        }
    },function(){
        //不具备该权限
    })
}

2.3 申请多个权限

适用于需要同时申请多个权限的场景(如 “相机 + 存储” 权限):

function requestPermissions() {
    var permissions = ['ohos.permission.APPROXIMATELY_LOCATION','ohos.permission.LOCATION'];
    cordova.plugins.permissions.requestPermissions(permissions, function(result){
        document.getElementById("requestPermissionInfos").innerHTML = JSON.stringify(result);
        if(result.hasPermission) {
          //具备权限
        }
    },function(){
         //不具备该权限
    })
}

许可证

本插件基于 Apache License 开源,详见 LICENSE 文件。

资源参考

  1. OHOShttps://gitcode.com/OpenHarmony-Cordova/cordova-plugin-android-permissions

  2. Android、ios插件说明https://www.npmjs.com/package/cordova-plugin-android-permissions