| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 06-May-2025 | - | 36 | 33 | ||
| entry/ | 06-May-2025 | - | 1,823 | 1,621 | ||
| hvigor/ | 06-May-2025 | - | 24 | 22 | ||
| screenshots/device/ | 06-May-2025 | - | ||||
| .gitignore | D | 06-May-2025 | 100 | 7 | 7 | |
| README.md | D | 06-May-2025 | 1.3 KiB | 43 | 21 | |
| README_zh.md | D | 06-May-2025 | 3.8 KiB | 81 | 53 | |
| build-profile.json5 | D | 06-May-2025 | 1 KiB | 43 | 41 | |
| hvigorfile.js | D | 06-May-2025 | 168 | 2 | 1 | |
| hvigorw | D | 06-May-2025 | 2.1 KiB | 62 | 28 | |
| hvigorw.bat | D | 06-May-2025 | 2 KiB | 73 | 56 | |
| oh-package.json5 | D | 06-May-2025 | 814 | 27 | 25 | |
| ohosTest.md | D | 06-May-2025 | 1.1 KiB | 11 | 11 |
README.md
1# Observer 2 3### Overview 4 5This sample demonstrates how to use observer APIs to subscribe to events of network status, signal status, call status, cellular data, and SIM card status changes. 6 7 8 9 10### Concepts 11 12`@ohos.telephony.observer` 13 14 A module that allows you to register observers to subscribe to events of mobile network, signal, call, and SIM card status changes. 15 16### Required Permissions 17 18The following permission must be declared in the `module.json5` file: 19 20**ohos.permission.GET_NETWORK_INFO**: Obtains the network status. 21 22**ohos.permission.READ_CALL_LOG**: Obtains the call status. 23 24### How to Use 25 261. Open the application and enable all event subscription switches. 27 282. Enable or disable the mobile network once to trigger a network status change. 29 303. Make a call to trigger a call status change. 31 324. Remove and insert the SIM card to trigger a SIM card status and signal status change. 33 345. Touch the **Details** button. A page is displayed, showing the related status change events. 35 36### Constraints 37 381. This sample can only be run on standard-system devices. 39 402. This sample demonstrates the stage model, which supports only API version 9. 41 423. This sample requires DevEco Studio 3.1 Canary1 (Build Version: 3.1.0.100) to compile and run. 43
README_zh.md
1 # 事件订阅 2 3### 介绍 4 5本示例通过observer接口订阅网络状态、信号状态、通话状态、蜂窝数据、sim状态等事件,并获取状态变化返回的结果。 6 7### 效果预览 8 9|主页| 10|--------------------------------| 11|| 12 13使用说明 14 151.打开应用,开启所有订阅事件开关。 16 172.开关一次网络,触发网络状态变化。 18 193.拨打一次电话,触发通话状态变化,手机号暂不支持显示,需要应用为系统应用同时预授权才能正常显示。 20 214.插拔一次sim卡,触发sim卡状态变化和信号状态变化。 22 235.点击**查看详情**按钮,跳转详情页,显示监听到的数据结果。 24 25### 工程目录 26``` 27entry/src/main/ets/ 28|---Application 29| |---AbilityStage.ts 30|---MainAbility 31| |---MainAbility.ts 32|---model 33| |---DetailData.ts // 详情数据 34| |---Logger.ts // 日志工具 35|---pages 36| |---Index.ets // 首页 37| |---Deatil.ets // 详情页面 38``` 39### 具体实现 40 41* 该示例使用NetworkState方法获取网络注册状态,SignalInformation方法获取网络信号强度信息,RadioTechnology方法获取无线接入技术,CallState方法获取通话状态码,DataConnectState方法描述蜂窝数据链路连接状态,DataFlowType方法描述蜂窝数据流类型,SimStateData方法获取SIM卡类型和状态等方法提供订阅管理功能。 42* 源码链接:[DetailData.ts](entry/src/main/ets/modle/DetailData.ts),[Index.ets](entry/src/main/ets/pages/Index.ets) 43* 接口参考:[@ohos.telephony.radio](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-telephony-kit/js-apis-radio.md),[@ohos.telephony.call](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-telephony-kit/js-apis-call.md),[@ohos.telephony.data](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-telephony-kit/js-apis-telephony-data.md),[@ohos.telephony.observer](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-telephony-kit/js-apis-observer.md) 44 45#### 相关概念 46 47observer: 通过注册相关监听事件,来监听手机网络、信号、通话、sim卡等状态,并返回相应的结果。 48 49### 相关权限 50 511.获取网络状态权限:[ohos.permission.GET_NETWORK_INFO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionget_network_info) 52 532.获取通话状态权限:[ohos.permission.READ_CALL_LOG](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionread_call_log) 54 55### 依赖 56 57不涉及。 58 59### 约束与限制 60 611.本示例仅支持标准系统上运行。 62 632.本示例需要插入SIM卡,目前该功能仅支持部分机型。 64 653.本示例已适配API version 9版本SDK,版本号:3.2.11.9。 66 674.本示例需要使用DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400, built on April 7, 2023)及以上版本才可编译运行。 68 695.本示例所配置的权限ohos.permission.READ_CALL_LOG为system_basic级别(相关权限级别可通过[权限定义列表](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md)查看),需要手动配置对应级别的权限签名(具体操作可查看[自动化签名方案](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/hapsigntool-overview.md)。 70 71### 下载 72 73如需单独下载本工程,执行如下命令: 74``` 75git init 76git config core.sparsecheckout true 77echo code/BasicFeature/Telephony/Observer/ > .git/info/sparse-checkout 78git remote add origin https://gitee.com/openharmony/applications_app_samples.git 79git pull origin master 80 81```