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

v0.8.9

Published

Cordova File Transfer Plugin

Downloads

148

Readme

cordova-plugin-badge

一个为Cordova应用提供应用图标角标(Badge)管理能力的插件,支持Android、iOS和HarmonyOS三平台,可灵活设置、获取、清除应用角标数值,适配主流移动操作系统特性。

概述

在移动应用开发中,应用图标角标是重要的消息提醒方式,可直观展示未读消息数、待办事项数等关键信息(如社交应用的未读消息、电商应用的待付款订单等)。cordova-plugin-badge插件通过封装原生平台API,为开发者提供了统一的角标管理接口,无需深入原生开发即可实现角标的设置、增量更新、获取及清除等功能,同时兼容不同平台的角标显示规则。

该插件具备以下核心特性:支持固定数值设置与增量调整、自动适配平台角标显示规则、支持角标状态持久化、提供完善的错误处理机制。

本文档主要说明在HarmonyOS系统中的应用。

支持平台

  • Android:API 21及以上(Android 5.0+),支持主流品牌机型(华为、小米、OPPO、vivo、三星等)

  • iOS:11.0及以上

  • HarmonyOS: 5.0及以上

安装

通过Cordova CLI或Ionic CLI即可快速安装插件,支持从npm仓库或GitHub仓库获取。

从npm安装(推荐)


# HCordova 
npm install -g hcordova

# Cordova CLI
cordova plugin add cordova-plugin-badge

从GitCode安装


hcordova plugin add https://gitcode.com/OpenHarmony-Cordova/cordova-plugin-badge.git --platform harmonyos

安装指定版本


hcordova plugin add [email protected] --platform harmonyos

卸载


# Cordova CLI
cordova plugin remove cordova-plugin-badge

# 指定HarmonyOS卸载
hcordova plugin remove cordova-plugin-badge --platform harmonyos

核心API

插件在全局对象plugin.notification.badge下暴露所有功能接口,所有API均支持Promise和传统回调函数两种调用方式,满足不同开发习惯需求。使用前需确保Cordova设备就绪事件(deviceready)已触发。

1. 设置角标数值

将应用角标设置为指定数值(数值为0时将清除角标),支持设置为非负整数。

方法签名


// 回调函数方式
window.Badge.set(count, successCallback)

2. 清除角标

plugin.notification.badge.clear()

3. HamronyOS不直接支持自增和自检角标,需要和真实的通知业务相结合

//不支持接口
get
increase 
decrease 
isSupported

使用示例

示例1:基础使用

设置角标数值、获取状态并在合适时机清除,适配消息通知场景。

//设置角标
function  setBadge() {
    plugin.notification.badge.set(5,function(){
        document.getElementById("badgeInfo").innerHTML = "设置成功";
    });
}

//清除角标
function clearBadge() {
    plugin.notification.badge.clear(function(){
        document.getElementById("badgeInfo").innerHTML = "设置成功";
    });
}

许可证

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

联系方式

资源参考

  1. HarmonyOShttps://gitcode.com/OpenHarmony-Cordova/cordova-plugin-badge

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