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-permission

v0.1.0

Published

Cordova Permission Plugin

Readme

cordova-plugin-permission

Cordova 平台权限管理插件,提供统一的 API 接口实现 Android、iOS、OHOS 平台的权限请求、检查与管理功能。支持动态权限申请、权限状态监听及系统权限设置页跳转,解决 Cordova 应用在不同平台下权限管理的差异化问题,保障应用合规性与功能可用性。本文档主要说明在OHOS系统中的应用。

重要提示: 申请权限建议下放到具体功能插件中,不建议提前申请权限,例如您的应用中有使用地理位置的权限,在具体的使用场景中再去申请,不推荐在启动应用时申请;例如cordova-plugin-geolocation插件,在使用地理位置是会自动弹窗,征求用户的同意,也无需安装该插件进行单独授权。

核心特性

  1. 跨平台统一 API:一套代码适配 Android、iOS、OHOS 权限管理,无需关注平台差异

  2. 动态权限支持:兼容 Android 6.0+ 动态权限机制与 iOS 10+ 权限申请逻辑、OHOS 5.0+

  3. 完整权限生命周期:支持权限检查、申请

安装指南

1. 基础安装(推荐)

# 安装 hcordova
npm install -g hcordova

# 全平台安装
hcordova plugin add cordova-plugin-permission

2. 安装指定版本

如需兼容特定 Cordova 版本,可指定版本号:

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

3. 开发版安装

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

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

4. 卸载插件

# 全平台卸载
cordova plugin remove cordova-plugin-permission

# 指定OHOS卸载
cordova plugin remove cordova-plugin-permission --platform ohos

快速开始

以下示例展示如何实现 “地理位置申请” 的完整流程,其他权限使用方式类似。

1. 权限申请前配置

需在主工程的modules.json5中的requestPermissions添加权限

{
  "name" : "ohos.permission.LOCATION",
  "reason": "$string:locationInfo",
  "usedScene": {
    "abilities": [
      "EntryAbility"
    ],
    "when": "always"
  }
},
{
  "name" : "ohos.permission.APPROXIMATELY_LOCATION",
  "reason": "$string:locationInfo",
  "usedScene": {
    "abilities": [
      "EntryAbility"
    ],
    "when": "always"
  }
},
{
  "name" : "ohos.permission.LOCATION_IN_BACKGROUND",
  "reason": "$string:locationInfo",
  "usedScene": {
    "abilities": [
      "EntryAbility"
    ],
    "when": "always"
  }
}

2. 基础使用示例(JavaScript)

//检查权限
function has() {
    var permissions = ['ohos.permission.APPROXIMATELY_LOCATION','ohos.permission.LOCATION'];
    window.plugins.Permission.has(permissions, function(result){
        document.getElementById("hasInfo").innerHTML = JSON.stringify(result);
    },function(){
    })
}

//申请权限
function request() {
    var permissions = ['ohos.permission.APPROXIMATELY_LOCATION','ohos.permission.LOCATION'];
    window.plugins.Permission.request(permissions, function(result){
        document.getElementById("requestInfo").innerHTML = JSON.stringify(result);
    },function(){
    })
}

详细 API 文档

1. 核心方法

1.1 检查权限状态

var permissions = ['ohos.permission.APPROXIMATELY_LOCATION','ohos.permission.LOCATION'];
window.plugins.Permission.has(permissions, function(result){
    if(result["ohos.permission.APPROXIMATELY_LOCATION"] && result["ohos.permission.LOCATION"]) {
      //已经授权
    } else {
      //未授权
    }
},function(){
    //未授权
})

1.2 申请权限

var permissions = ['ohos.permission.APPROXIMATELY_LOCATION','ohos.permission.LOCATION'];
window.plugins.Permission.request(permissions, function(result){
    if(result["ohos.permission.APPROXIMATELY_LOCATION"] && result["ohos.permission.LOCATION"]) {
      //已经授权
    } else {
      //未授权
    }
},function(){
    //未授权
})

权限申请最佳实践

1. 遵循 “必要时申请” 原则

  • 避免应用启动时一次性申请所有权限,在用户使用对应功能时再申请

2. 提供清晰的权限申请理由

  • 根据上架的应用规则,应先弹出使用权限的具体原因,示例:申请位置权限前,显示 “需要位置权限以推荐附近的服务”,然后再弹系统弹窗征求同意。

许可证

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

资源参考

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

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