1e41f4b71Sopenharmony_ci# @ohos.telephony.observer (Observer) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **observer** module provides event subscription management functions. With the APIs provided by this module, you can register or unregister an observer that listens cell information events (for the SIM card in the specified slot). 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci>**NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci>This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.telephony.observer (Observer)](js-apis-observer.md). 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Modules to Import 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```ts 14e41f4b71Sopenharmony_ciimport { observer } from '@kit.TelephonyKit'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci## observer.on('cellInfoChange')<sup>8+</sup> 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_cion\(type: \'cellInfoChange\', callback: Callback\<Array\<CellInformation\>\>\): void 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ciRegisters an observer for cell information change events. This API uses an asynchronous callback to return the result. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**System API**: This is a system API. 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.StateRegistry 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci**Parameters** 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 33e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------------- | ---- |------------------------------------------| 34e41f4b71Sopenharmony_ci| type | string | Yes | Cell information change event. This field has a fixed value of **cellInfoChange**.| 35e41f4b71Sopenharmony_ci| callback | Callback\<Array\<[CellInformation](js-apis-radio.md#cellinformation8)\>\> | Yes | Callback used to return the result. | 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**Error codes** 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci| ID| Error Message | 42e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | 43e41f4b71Sopenharmony_ci| 201 | Permission denied. | 44e41f4b71Sopenharmony_ci| 202 | Non-system applications use system APIs. | 45e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 46e41f4b71Sopenharmony_ci| 8300001 | Invalid parameter value. | 47e41f4b71Sopenharmony_ci| 8300002 | Service connection failed. | 48e41f4b71Sopenharmony_ci| 8300003 | System internal error. | 49e41f4b71Sopenharmony_ci| 8300999 | Unknown error. | 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci**Example** 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci```ts 54e41f4b71Sopenharmony_ciimport { radio } from '@kit.TelephonyKit'; 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ciobserver.on('cellInfoChange', (data: Array<radio.CellInformation>) => { 57e41f4b71Sopenharmony_ci console.log("on cellInfoChange, data:" + JSON.stringify(data)); 58e41f4b71Sopenharmony_ci}); 59e41f4b71Sopenharmony_ci``` 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci## observer.on('cellInfoChange')<sup>8+</sup> 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_cion\(type: \'cellInfoChange\', options: ObserverOptions, callback: Callback\<Array\<CellInformation\>\>\): void 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ciRegisters an observer for signal status change events of the SIM card in the specified slot. This API uses an asynchronous callback to return the execution result. 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci**System API**: This is a system API. 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.StateRegistry 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci**Parameters** 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 77e41f4b71Sopenharmony_ci| ------ |--------------------------------------------------| ---- |--------------------------------------------| 78e41f4b71Sopenharmony_ci| type | string | Yes | Cell information change event. This field has a fixed value of **cellInfoChange**.| 79e41f4b71Sopenharmony_ci| options | [ObserverOptions](js-apis-observer.md#observeroptions11) | Yes | Event subscription parameters. | 80e41f4b71Sopenharmony_ci| callback | Callback\<Array\<[CellInformation](js-apis-radio.md#cellinformation8)\>\> | Yes | Callback used to return the result. | 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**Error codes** 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci| ID| Error Message | 87e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | 88e41f4b71Sopenharmony_ci| 201 | Permission denied. | 89e41f4b71Sopenharmony_ci| 202 | Non-system applications use system APIs. | 90e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 91e41f4b71Sopenharmony_ci| 8300001 | Invalid parameter value. | 92e41f4b71Sopenharmony_ci| 8300002 | Service connection failed. | 93e41f4b71Sopenharmony_ci| 8300003 | System internal error. | 94e41f4b71Sopenharmony_ci| 8300999 | Unknown error. | 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci**Example** 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci```ts 99e41f4b71Sopenharmony_ciimport { radio } from '@kit.TelephonyKit'; 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_cilet options: observer.ObserverOptions = { 102e41f4b71Sopenharmony_ci slotId: 0 103e41f4b71Sopenharmony_ci} 104e41f4b71Sopenharmony_ciobserver.on('cellInfoChange', options, (data: Array<radio.CellInformation>) => { 105e41f4b71Sopenharmony_ci console.log("on cellInfoChange, data:" + JSON.stringify(data)); 106e41f4b71Sopenharmony_ci}); 107e41f4b71Sopenharmony_ci``` 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci## observer.off('cellInfoChange')<sup>8+</sup> 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_cioff\(type: \'cellInfoChange\', callback?: Callback\<Array\<CellInformation\>\>\): void 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ciUnregisters the observer for cell information change events. This API uses an asynchronous callback to return the result. 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci>**NOTE** 117e41f4b71Sopenharmony_ci> 118e41f4b71Sopenharmony_ci>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci**System API**: This is a system API. 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.StateRegistry 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci**Parameters** 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 127e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | 128e41f4b71Sopenharmony_ci| type | string | Yes | Cell information change event. This field has a fixed value of **cellInfoChange**. | 129e41f4b71Sopenharmony_ci| callback | Callback\<Array\<[CellInformation](js-apis-radio.md#cellinformation8)\>\> | No | Callback used to return the result.| 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci**Error codes** 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci| ID| Error Message | 136e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | 137e41f4b71Sopenharmony_ci| 202 | Non-system applications use system APIs. | 138e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 139e41f4b71Sopenharmony_ci| 8300001 | Invalid parameter value. | 140e41f4b71Sopenharmony_ci| 8300002 | Service connection failed. | 141e41f4b71Sopenharmony_ci| 8300003 | System internal error. | 142e41f4b71Sopenharmony_ci| 8300999 | Unknown error. | 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci**Example** 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci```ts 147e41f4b71Sopenharmony_ciimport { radio } from '@kit.TelephonyKit'; 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_cilet callback: (data: Array<radio.CellInformation>) => void = (data: Array<radio.CellInformation>) => { 150e41f4b71Sopenharmony_ci console.log("on cellInfoChange, data:" + JSON.stringify(data)); 151e41f4b71Sopenharmony_ci} 152e41f4b71Sopenharmony_ciobserver.on('cellInfoChange', callback); 153e41f4b71Sopenharmony_ci// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. 154e41f4b71Sopenharmony_ciobserver.off('cellInfoChange', callback); 155e41f4b71Sopenharmony_ciobserver.off('cellInfoChange'); 156e41f4b71Sopenharmony_ci``` 157