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