| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 06-May-2025 | - | 35 | 32 | ||
| entry/ | 06-May-2025 | - | 564 | 486 | ||
| hvigor/ | 06-May-2025 | - | 6 | 5 | ||
| screenshots/device/ | 06-May-2025 | - | ||||
| .gitignore | D | 06-May-2025 | 133 | 12 | 12 | |
| README_zh.md | D | 06-May-2025 | 3.2 KiB | 77 | 56 | |
| build-profile.json5 | D | 06-May-2025 | 1.3 KiB | 57 | 55 | |
| hvigorfile.ts | D | 06-May-2025 | 843 | 22 | 5 | |
| oh-package.json5 | D | 06-May-2025 | 200 | 11 | 10 | |
| ohosTest.md | D | 06-May-2025 | 611 | 12 | 6 |
README_zh.md
1# 通知服务 2 3### 介绍 4 5本示例主要介绍开发者如何调用Native Notification接口使用通知服务。当前功能包含查询当前应用通知使能状态。 6 7### 效果预览 8 9| 主页 | 弹窗显示关闭通知使能状态 | 弹窗显示开启通知使能状态 | 10| ------------------------------------ | --------------------------------------------- | --------------------------------------------------- | 11|  |  |  | 12 13使用说明 14 151. 安装编译生成的Hap包,并打开应用。 162. 点击页面中的"Check notification enabled"按钮,页面将弹窗显示该应用的通知使能状态。 173. 点击弹窗中的"OK"按钮则返回主页面。 184. 通过下拉通知中心页面,点击设置按钮进入通知管理页面,修改当前应用的通知使能状态后,可以再次点击按钮查询。 19 20### 工程目录 21 22``` 23entry/src/main/ 24|---main 25| |---cpp 26| | |---types 27| | | |---libentry 28| | | | |---index.d.ts // 接口导出 29| | | | |---oh-package.json5 30| | |---NativeNotificationAdaptor.cpp // 调用native接口 31| | |---CMakeLists.txt // 编译脚本 32| |---ets 33| | |---entryability 34| | | |---EntryAbility.ets 35| | |---pages 36| | | |---Index.ets // 首页 37| |---resources // 静态资源 38|---ohosTest 39| |---ets 40| | |---tests 41| | | |---Ability.test.ets // 自动化测试用例 42``` 43 44### 具体实现 45 46通过在IDE中创建Native C++工程,在C++代码中定义对外接口为isNotificationEnabled,映射C++接口IsNotificationEnabled。通过获取JS的资源对象,并转化为Native的资源对象,即可调用对外开放的Native接口。在JS侧导入"libentry.so",调用src/main/cpp/type/libentry/index.d.ts中声明的接口。源代码参考:[NativeNotificationAdaptor.cpp](entry/src/main/cpp/NativeNotificationAdaptor.cpp)。其中涉及的相关接口: 47 48| 接口名 | 描述 | 49|:-------------------------------|:-------------------------------------------------------------------------------------------------------| 50| bool OH_Notification_IsNotificationEnabled(void); | 查询当前应用通知使能状态。 | 51 52### 相关权限 53 54不涉及 55 56### 依赖 57 58不涉及。 59 60### 约束与限制 61 621. 本示例仅支持标准系统上运行,支持设备:RK3568; 632. 本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.43; 643. 本示例需要使用DevEco Studio NEXT Release(5.0.3.900)及以上版本才可编译运行; 65 66### 下载 67 68如需单独下载本工程,执行如下命令: 69 70``` 71git init 72git config core.sparsecheckout true 73echo code/BasicFeature/Native/NdkNotification/ > .git/info/sparse-checkout 74git remote add origin https://gitee.com/openharmony/applications_app_samples.git 75git pull origin master 76``` 77