1# @ohos.telephony.observer (Observer) 2 3The **observer** module provides event subscription management functions. You can register or unregister an observer that listens for the following events: network status change, signal status change, call status change, cellular data connection status, uplink and downlink data flow status of cellular data services, and SIM status change. 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 10## Modules to Import 11 12```ts 13import { observer } from '@kit.TelephonyKit'; 14``` 15 16## observer.on('networkStateChange') 17 18on\(type: \'networkStateChange\', callback: Callback\<NetworkState\>\): void 19 20Registers an observer for network status change events. This API uses an asynchronous callback to return the execution result. 21 22**Required permission**: ohos.permission.GET_NETWORK_INFO 23 24**System capability**: SystemCapability.Telephony.StateRegistry 25 26**Parameters** 27 28| Name | Type | Mandatory| Description | 29| -------- | --------------------------------------------------------- | ---- | ---------------------------------------------------------------- | 30| type | string | Yes | Network status change event. This field has a fixed value of **networkStateChange**. | 31| callback | Callback\<[NetworkState](js-apis-radio.md#networkstate)\> | Yes | Callback used to return the result. For details, see [NetworkState](js-apis-radio.md#networkstate).| 32 33**Error codes** 34 35For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 36 37| ID| Error Message | 38| -------- | -------------------------------------------- | 39| 201 | Permission denied. | 40| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 41| 8300001 | Invalid parameter value. | 42| 8300002 | Service connection failed. | 43| 8300003 | System internal error. | 44| 8300999 | Unknown error. | 45 46**Example** 47 48```ts 49observer.on('networkStateChange', (data: observer.NetworkState) => { 50 console.log("on networkStateChange, data:" + JSON.stringify(data)); 51}); 52``` 53 54 55## observer.on('networkStateChange') 56 57on\(type: \'networkStateChange\', options: ObserverOptions, callback: Callback\<NetworkState\>\): void 58 59Registers an observer for network status change events of the SIM card in the specified slot. This API uses an asynchronous callback to return the execution result. 60 61**Required permission**: ohos.permission.GET_NETWORK_INFO 62 63**System capability**: SystemCapability.Telephony.StateRegistry 64 65**Parameters** 66 67| Name | Type | Mandatory| Description | 68| -------- | --------------------------------------------------------- | ---- | ---------------------------------------------------------------- | 69| type | string | Yes | Network status change event. This field has a fixed value of **networkStateChange**. | 70| options | [ObserverOptions](#observeroptions11) | Yes | Event subscription parameters. | 71| callback | Callback\<[NetworkState](js-apis-radio.md#networkstate)\> | Yes | Callback used to return the result. For details, see [NetworkState](js-apis-radio.md#networkstate).| 72 73**Error codes** 74 75For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 76 77| ID| Error Message | 78| -------- | -------------------------------------------- | 79| 201 | Permission denied. | 80| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 81| 8300001 | Invalid parameter value. | 82| 8300002 | Service connection failed. | 83| 8300003 | System internal error. | 84| 8300999 | Unknown error. | 85 86**Example** 87 88```ts 89let options: observer.ObserverOptions = { 90 slotId: 0 91} 92observer.on('networkStateChange', options, (data: observer.NetworkState) => { 93 console.log("on networkStateChange, data:" + JSON.stringify(data)); 94}); 95``` 96 97 98## observer.off('networkStateChange') 99 100off\(type: \'networkStateChange\', callback?: Callback\<NetworkState\>\): void 101 102Unregisters the observer for network status change events. This API uses an asynchronous callback to return the execution result. 103 104>**NOTE** 105> 106>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. 107 108**System capability**: SystemCapability.Telephony.StateRegistry 109 110**Parameters** 111 112| Name | Type | Mandatory| Description | 113| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | 114| type | string | Yes | Network status change event. This field has a fixed value of **networkStateChange**. | 115| callback | Callback\<[NetworkState](js-apis-radio.md#networkstate)\> | No | Callback used to return the result. For details, see [NetworkState](js-apis-radio.md#networkstate).| 116 117**Error codes** 118 119For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 120 121| ID| Error Message | 122| -------- | -------------------------------------------- | 123| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 124| 8300001 | Invalid parameter value. | 125| 8300002 | Service connection failed. | 126| 8300003 | System internal error. | 127| 8300999 | Unknown error. | 128 129**Example** 130 131```ts 132let callback: (data: observer.NetworkState) => void = (data: observer.NetworkState) => { 133 console.log("on networkStateChange, data:" + JSON.stringify(data)); 134} 135observer.on('networkStateChange', callback); 136// 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. 137observer.off('networkStateChange', callback); 138observer.off('networkStateChange'); 139``` 140 141## observer.on('signalInfoChange') 142 143on\(type: \'signalInfoChange\', callback: Callback\<Array\<SignalInformation\>\>): void 144 145Registers an observer for signal status change events. This API uses an asynchronous callback to return the execution result. 146 147**System capability**: SystemCapability.Telephony.StateRegistry 148 149**Parameters** 150 151| Name | Type | Mandatory| Description | 152| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 153| type | string | Yes | Signal status change event. This field has a fixed value of **signalInfoChange**. | 154| callback | Callback\<Array\<[SignalInformation](js-apis-radio.md#signalinformation)\>\> | Yes | Callback used to return the result. For details, see [SignalInformation](js-apis-radio.md#signalinformation).| 155 156**Error codes** 157 158For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 159 160| ID| Error Message | 161| -------- | -------------------------------------------- | 162| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 163| 8300001 | Invalid parameter value. | 164| 8300002 | Service connection failed. | 165| 8300003 | System internal error. | 166| 8300999 | Unknown error. | 167 168**Example** 169 170```ts 171import { radio } from '@kit.TelephonyKit'; 172 173observer.on('signalInfoChange', (data: Array<radio.SignalInformation>) => { 174 console.log("on signalInfoChange, data:" + JSON.stringify(data)); 175}); 176``` 177 178 179## observer.on('signalInfoChange') 180 181on\(type: \'signalInfoChange\', options: ObserverOptions, callback: Callback\<Array\<SignalInformation\>\>): void 182 183Registers 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. 184 185**System capability**: SystemCapability.Telephony.StateRegistry 186 187**Parameters** 188 189| Name | Type | Mandatory| Description | 190| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 191| type | string | Yes | Signal status change event. This field has a fixed value of **signalInfoChange**. | 192| options | [ObserverOptions](#observeroptions11) | Yes | Event subscription parameters. | 193| callback | Callback\<Array\<[SignalInformation](js-apis-radio.md#signalinformation)\>\> | Yes | Callback used to return the result. For details, see [SignalInformation](js-apis-radio.md#signalinformation).| 194 195**Error codes** 196 197For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 198 199| ID| Error Message | 200| -------- | -------------------------------------------- | 201| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 202| 8300001 | Invalid parameter value. | 203| 8300002 | Service connection failed. | 204| 8300003 | System internal error. | 205| 8300999 | Unknown error. | 206 207**Example** 208 209```ts 210import { radio } from '@kit.TelephonyKit'; 211 212let options: observer.ObserverOptions = { 213 slotId: 0 214} 215observer.on('signalInfoChange', options, (data: Array<radio.SignalInformation>) => { 216 console.log("on signalInfoChange, data:" + JSON.stringify(data)); 217}); 218``` 219 220 221## observer.off('signalInfoChange') 222 223off\(type: \'signalInfoChange\', callback?: Callback\<Array\<SignalInformation\>\>): void 224 225Unregisters the observer for signal status change events. This API uses an asynchronous callback to return the execution result. 226 227>**NOTE** 228> 229>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. 230 231**System capability**: SystemCapability.Telephony.StateRegistry 232 233**Parameters** 234 235| Name | Type | Mandatory| Description | 236| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 237| type | string | Yes | Signal status change event. This field has a fixed value of **signalInfoChange**. | 238| callback | Callback\<Array\<[SignalInformation](js-apis-radio.md#signalinformation)\>\> | No | Callback used to return the result. For details, see [SignalInformation](js-apis-radio.md#signalinformation).| 239 240**Error codes** 241 242For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 243 244| ID| Error Message | 245| -------- | -------------------------------------------- | 246| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 247| 8300001 | Invalid parameter value. | 248| 8300002 | Service connection failed. | 249| 8300003 | System internal error. | 250| 8300999 | Unknown error. | 251 252**Example** 253 254```ts 255import { radio } from '@kit.TelephonyKit'; 256 257let callback: (data: Array<radio.SignalInformation>) => void = (data: Array<radio.SignalInformation>) => { 258 console.log("on signalInfoChange, data:" + JSON.stringify(data)); 259} 260observer.on('signalInfoChange', callback); 261// 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. 262observer.off('signalInfoChange', callback); 263observer.off('signalInfoChange'); 264``` 265 266 267## observer.on('callStateChange') 268 269on(type: 'callStateChange', callback: Callback\<CallStateInfo\>): void 270 271Registers an observer for call status change events. This API uses an asynchronous callback to return the execution result. 272 273>**NOTE** 274> 275>Before using this API, you must declare the **ohos.permission.READ_CALL_LOG** permission (a system permission). 276 277**System capability**: SystemCapability.Telephony.StateRegistry 278 279**Parameters** 280 281| Name | Type | Mandatory| Description | 282| -------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 283| type | string | Yes | Call status change event. This field has a fixed value of **callStateChange**. | 284| callback | Callback\<[CallStateInfo](#callstateinfo11)\> | Yes | Callback used to return the result. For details, see [CallState](js-apis-call.md#callstate).<br>**number**: phone number.| 285 286**Error codes** 287 288For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 289 290| ID| Error Message | 291| -------- | -------------------------------------------- | 292| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 293| 8300001 | Invalid parameter value. | 294| 8300002 | Service connection failed. | 295| 8300003 | System internal error. | 296| 8300999 | Unknown error. | 297 298**Example** 299 300```ts 301observer.on('callStateChange', (data: observer.CallStateInfo) => { 302 console.log("on callStateChange, data:" + JSON.stringify(data)); 303}); 304``` 305 306 307## observer.on('callStateChange') 308 309on(type: 'callStateChange', options: ObserverOptions, callback: Callback\<CallStateInfo\>): void 310 311Registers an observer for call status change events. This API uses an asynchronous callback to return the execution result. 312 313>**NOTE** 314> 315>Before using this API, you must declare the **ohos.permission.READ_CALL_LOG** permission (a system permission). 316 317**System capability**: SystemCapability.Telephony.StateRegistry 318 319**Parameters** 320 321| Name | Type | Mandatory| Description | 322| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 323| type | string | Yes | Call status change event. This field has a fixed value of **callStateChange**. | 324| options | [ObserverOptions](#observeroptions11) | Yes | Event subscription parameters. | 325| callback | Callback\<[CallStateInfo](#callstateinfo11)\> | Yes | Callback used to return the result. For details, see [CallState](js-apis-call.md#callstate).<br>**number**: phone number.| 326 327**Error codes** 328 329For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 330 331| ID| Error Message | 332| -------- | -------------------------------------------- | 333| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 334| 8300001 | Invalid parameter value. | 335| 8300002 | Service connection failed. | 336| 8300003 | System internal error. | 337| 8300999 | Unknown error. | 338 339**Example** 340 341```ts 342let options: observer.ObserverOptions = { 343 slotId: 0 344} 345observer.on('callStateChange', options, (data: observer.CallStateInfo) => { 346 console.log("on callStateChange, data:" + JSON.stringify(data)); 347}); 348``` 349 350 351## observer.off('callStateChange') 352 353off(type: 'callStateChange', callback?: Callback\<CallStateInfo\>): void 354 355Unregisters the observer for call status change events. This API uses an asynchronous callback to return the execution result. 356 357>**NOTE** 358> 359>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. 360 361**System capability**: SystemCapability.Telephony.StateRegistry 362 363**Parameters** 364 365| Name | Type | Mandatory| Description | 366| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 367| type | string | Yes | Call status change event. This field has a fixed value of **callStateChange**. | 368| callback | Callback\<[CallStateInfo](#callstateinfo11)\> | No | Callback used to return the result. For details, see [CallState](js-apis-call.md#callstate).<br>**number**: phone number.| 369 370**Error codes** 371 372For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 373 374| ID| Error Message | 375| -------- | -------------------------------------------- | 376| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 377| 8300001 | Invalid parameter value. | 378| 8300002 | Service connection failed. | 379| 8300003 | System internal error. | 380| 8300999 | Unknown error. | 381 382**Example** 383 384```ts 385let callback: (data: observer.CallStateInfo) => void = (data: observer.CallStateInfo) => { 386 console.log("on callStateChange, data:" + JSON.stringify(data)); 387} 388observer.on('callStateChange', callback); 389// 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. 390observer.off('callStateChange', callback); 391observer.off('callStateChange'); 392``` 393 394 395## observer.on('cellularDataConnectionStateChange')<sup>7+</sup> 396 397on\(type: 'cellularDataConnectionStateChange', callback: Callback\<DataConnectionStateInfo\>\): void 398 399Registers an observer for connection status change events of the cellular data link. This API uses an asynchronous callback to return the result. 400 401**System capability**: SystemCapability.Telephony.StateRegistry 402 403**Parameters** 404 405| Name | Type | Mandatory| Description | 406| -------- | --------------------------------- | ---- | -------------------------------------------------------------------- | 407| type | string | Yes | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.| 408| callback | Callback\<[DataConnectionStateInfo](#dataconnectionstateinfo11)\> | Yes | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).| 409 410**Error codes** 411 412For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 413 414| ID| Error Message | 415| -------- | -------------------------------------------- | 416| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 417| 8300001 | Invalid parameter value. | 418| 8300002 | Service connection failed. | 419| 8300003 | System internal error. | 420| 8300999 | Unknown error. | 421 422**Example** 423 424```ts 425observer.on('cellularDataConnectionStateChange', (data: observer.DataConnectionStateInfo) => { 426 console.log("on cellularDataConnectionStateChange, data:" + JSON.stringify(data)); 427}); 428``` 429 430 431## observer.on('cellularDataConnectionStateChange')<sup>7+</sup> 432 433on\(type: 'cellularDataConnectionStateChange', options: ObserverOptions, callback: Callback\<DataConnectionStateInfo\>\): void 434 435Registers an observer for connection status change events of the cellular data link over the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 436 437**System capability**: SystemCapability.Telephony.StateRegistry 438 439**Parameters** 440 441| Name | Type | Mandatory| Description | 442| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 443| type | string | Yes | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.| 444| options | [ObserverOptions](#observeroptions11) | Yes | Event subscription parameters. | 445| callback | Callback\<[DataConnectionStateInfo](#dataconnectionstateinfo11)\> | Yes | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).| 446 447**Error codes** 448 449For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 450 451| ID| Error Message | 452| -------- | -------------------------------------------- | 453| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 454| 8300001 | Invalid parameter value. | 455| 8300002 | Service connection failed. | 456| 8300003 | System internal error. | 457| 8300999 | Unknown error. | 458 459**Example** 460 461```ts 462let options: observer.ObserverOptions = { 463 slotId: 0 464} 465observer.on('cellularDataConnectionStateChange', options, (data: observer.DataConnectionStateInfo) => { 466 console.log("on cellularDataConnectionStateChange, data:" + JSON.stringify(data)); 467}); 468``` 469 470 471## observer.off('cellularDataConnectionStateChange')<sup>7+</sup> 472 473off\(type: 'cellularDataConnectionStateChange', callback?: Callback\<DataConnectionStateInfo\>\): void 474 475Unregisters the observer for connection status change events of the cellular data link. This API uses an asynchronous callback to return the result. 476 477>**NOTE** 478> 479>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. 480 481**System capability**: SystemCapability.Telephony.StateRegistry 482 483**Parameters** 484 485| Name | Type | Mandatory| Description | 486| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 487| type | string | Yes | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.| 488| callback | Callback\<[DataConnectionStateInfo](#dataconnectionstateinfo11)\> | No | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).| 489 490**Error codes** 491 492For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 493 494| ID| Error Message | 495| -------- | -------------------------------------------- | 496| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 497| 8300001 | Invalid parameter value. | 498| 8300002 | Service connection failed. | 499| 8300003 | System internal error. | 500| 8300999 | Unknown error. | 501 502**Example** 503 504```ts 505let callback: (data: observer.DataConnectionStateInfo) => void = (data: observer.DataConnectionStateInfo) => { 506 console.log("on cellularDataConnectionStateChange, data:" + JSON.stringify(data)); 507} 508observer.on('cellularDataConnectionStateChange', callback); 509// 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. 510observer.off('cellularDataConnectionStateChange', callback); 511observer.off('cellularDataConnectionStateChange'); 512``` 513 514 515## observer.on('cellularDataFlowChange')<sup>7+</sup> 516 517on\(type: 'cellularDataFlowChange', callback: Callback\<DataFlowType\>\): void 518 519Registers an observer for the uplink and downlink data flow status change events of the cellular data service. This API uses an asynchronous callback to return the result. 520 521**System capability**: SystemCapability.Telephony.StateRegistry 522 523**Parameters** 524 525| Name | Type | Mandatory| Description | 526| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 527| type | string | Yes | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**. | 528| callback | Callback\<[DataFlowType](js-apis-telephony-data.md#dataflowtype)\> | Yes | Callback used to return the result. For details, see [DataFlowType](js-apis-telephony-data.md#dataflowtype).| 529 530**Error codes** 531 532For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 533 534| ID| Error Message | 535| -------- | -------------------------------------------- | 536| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 537| 8300001 | Invalid parameter value. | 538| 8300002 | Service connection failed. | 539| 8300003 | System internal error. | 540| 8300999 | Unknown error. | 541 542**Example** 543 544```ts 545import { data } from '@kit.TelephonyKit'; 546 547observer.on('cellularDataFlowChange', (data: data.DataFlowType) => { 548 console.log("on cellularDataFlowChange, data:" + JSON.stringify(data)); 549}); 550``` 551 552 553## observer.on('cellularDataFlowChange')<sup>7+</sup> 554 555on\(type: 'cellularDataFlowChange', options: ObserverOptions, callback: Callback\<DataFlowType\>\): void 556 557Registers an observer for the uplink and downlink data flow status change events of the cellular data service on the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 558 559**System capability**: SystemCapability.Telephony.StateRegistry 560 561**Parameters** 562 563| Name | Type | Mandatory| Description | 564| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 565| type | string | Yes | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**. | 566| options | [ObserverOptions](#observeroptions11) | Yes | Event subscription parameters. | 567| callback | Callback\<[DataFlowType](js-apis-telephony-data.md#dataflowtype)\> | Yes | Callback used to return the result. For details, see [DataFlowType](js-apis-telephony-data.md#dataflowtype).| 568 569**Error codes** 570 571For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 572 573| ID| Error Message | 574| -------- | -------------------------------------------- | 575| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 576| 8300001 | Invalid parameter value. | 577| 8300002 | Service connection failed. | 578| 8300003 | System internal error. | 579| 8300999 | Unknown error. | 580 581**Example** 582 583```ts 584import { data } from '@kit.TelephonyKit'; 585 586let options: observer.ObserverOptions = { 587 slotId: 0 588} 589observer.on('cellularDataFlowChange', options, (data: data.DataFlowType) => { 590 console.log("on cellularDataFlowChange, data:" + JSON.stringify(data)); 591}); 592``` 593 594 595## observer.off('cellularDataFlowChange')<sup>7+</sup> 596 597off\(type: 'cellularDataFlowChange', callback?: Callback\<DataFlowType\>\): void 598 599Unregisters the observer for the uplink and downlink data flow status change events of the cellular data service. This API uses an asynchronous callback to return the result. 600 601>**NOTE** 602> 603>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. 604 605**System capability**: SystemCapability.Telephony.StateRegistry 606 607**Parameters** 608 609| Name | Type | Mandatory| Description | 610| -------- | ------------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 611| type | string | Yes | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**. | 612| callback | Callback\<[DataFlowType](js-apis-telephony-data.md#dataflowtype)\> | No | Callback used to return the result. For details, see [DataFlowType](js-apis-telephony-data.md#dataflowtype).| 613 614**Error codes** 615 616For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 617 618| ID| Error Message | 619| -------- | -------------------------------------------- | 620| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 621| 8300001 | Invalid parameter value. | 622| 8300002 | Service connection failed. | 623| 8300003 | System internal error. | 624| 8300999 | Unknown error. | 625 626**Example** 627 628```ts 629import { data } from '@kit.TelephonyKit'; 630 631let callback: (data: data.DataFlowType) => void = (data: data.DataFlowType) => { 632 console.log("on cellularDataFlowChange, data:" + JSON.stringify(data)); 633} 634observer.on('cellularDataFlowChange', callback); 635// 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. 636observer.off('cellularDataFlowChange', callback); 637observer.off('cellularDataFlowChange'); 638``` 639 640 641## observer.on('simStateChange')<sup>7+</sup> 642 643on\(type: 'simStateChange', callback: Callback\<SimStateData\>\): void 644 645Registers an observer for SIM card status change events. This API uses an asynchronous callback to return the result. 646 647**System capability**: SystemCapability.Telephony.StateRegistry 648 649**Parameters** 650 651| Name | Type | Mandatory| Description | 652| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 653| type | string | Yes | SIM status change event. This field has a fixed value of **simStateChange**. | 654| callback | Callback\<[SimStateData](#simstatedata7)\> | Yes | Callback used to return the result.| 655 656**Error codes** 657 658For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 659 660| ID| Error Message | 661| -------- | -------------------------------------------- | 662| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 663| 8300001 | Invalid parameter value. | 664| 8300002 | Service connection failed. | 665| 8300003 | System internal error. | 666| 8300999 | Unknown error. | 667 668**Example** 669 670```ts 671observer.on('simStateChange', (data: observer.SimStateData) => { 672 console.log("on simStateChange, data:" + JSON.stringify(data)); 673}); 674``` 675 676 677## observer.on('simStateChange')<sup>7+</sup> 678 679on\(type: 'simStateChange', options: ObserverOptions, callback: Callback\<SimStateData\>\): void 680 681Registers an observer for status change events of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 682 683**System capability**: SystemCapability.Telephony.StateRegistry 684 685**Parameters** 686 687| Name | Type | Mandatory| Description | 688| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 689| type | string | Yes | SIM status change event. This field has a fixed value of **simStateChange**. | 690| options | [ObserverOptions](#observeroptions11) | Yes | Event subscription parameters. | 691| callback | Callback\<[SimStateData](#simstatedata7)\> | Yes | Callback used to return the result.| 692 693**Error codes** 694 695For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 696 697| ID| Error Message | 698| -------- | -------------------------------------------- | 699| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 700| 8300001 | Invalid parameter value. | 701| 8300002 | Service connection failed. | 702| 8300003 | System internal error. | 703| 8300999 | Unknown error. | 704 705**Example** 706 707```ts 708let options: observer.ObserverOptions = { 709 slotId: 0 710} 711observer.on('simStateChange', options, (data: observer.SimStateData) => { 712 console.log("on simStateChange, data:" + JSON.stringify(data)); 713}); 714``` 715 716 717## observer.off('simStateChange')<sup>7+</sup> 718 719off\(type: 'simStateChange', callback?: Callback\<SimStateData\>\): void 720 721Unregisters the observer for SIM card status change events. This API uses an asynchronous callback to return the result. 722 723>**NOTE** 724> 725>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. 726 727**System capability**: SystemCapability.Telephony.StateRegistry 728 729**Parameters** 730 731| Name | Type | Mandatory| Description | 732| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 733| type | string | Yes | SIM status change event. This field has a fixed value of **simStateChange**. | 734| callback | Callback\<[SimStateData](#simstatedata7)\> | No | Callback used to return the result.| 735 736**Error codes** 737 738For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 739 740| ID| Error Message | 741| -------- | -------------------------------------------- | 742| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 743| 8300001 | Invalid parameter value. | 744| 8300002 | Service connection failed. | 745| 8300003 | System internal error. | 746| 8300999 | Unknown error. | 747 748**Example** 749 750```ts 751let callback: (data: observer.SimStateData) => void = (data: observer.SimStateData) => { 752 console.log("on simStateChange, data:" + JSON.stringify(data)); 753} 754observer.on('simStateChange', callback); 755// 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. 756observer.off('simStateChange', callback); 757observer.off('simStateChange'); 758``` 759 760## observer.on('iccAccountInfoChange')<sup>10+</sup> 761 762on\(type: 'iccAccountInfoChange', callback: Callback\<void\>\): void 763 764Registers an observer for account information change events of the SIM card. This API uses an asynchronous callback to return the result. 765 766**System capability**: SystemCapability.Telephony.StateRegistry 767 768**Parameters** 769 770| Name | Type | Mandatory| Description | 771| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 772| type | string | Yes | Account information change event. This field has a fixed value of **iccAccountInfoChange**. | 773| callback | Callback\<void\> | Yes | Callback used to return the result.| 774 775**Error codes** 776 777For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 778 779| ID| Error Message | 780| -------- | -------------------------------------------- | 781| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 782| 8300001 | Invalid parameter value. | 783| 8300002 | Service connection failed. | 784| 8300003 | System internal error. | 785| 8300999 | Unknown error. | 786 787**Example** 788 789```ts 790observer.on('iccAccountInfoChange', () => { 791 console.log("on iccAccountInfoChange success"); 792}); 793``` 794 795 796## observer.off('iccAccountInfoChange')<sup>10+</sup> 797 798off\(type: 'iccAccountInfoChange', callback?: Callback\<void\>\): void 799 800Unregisters the observer for account information change events of the SIM card. This API uses an asynchronous callback to return the result. 801 802>**NOTE** 803> 804>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. 805 806**System capability**: SystemCapability.Telephony.StateRegistry 807 808**Parameters** 809 810| Name | Type | Mandatory| Description | 811| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 812| type | string | Yes | Account information change event. This field has a fixed value of **iccAccountInfoChange**. | 813| callback | Callback\<void\> | No | Callback used to return the result.| 814 815**Error codes** 816 817For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 818 819| ID| Error Message | 820| -------- | -------------------------------------------- | 821| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 822| 8300001 | Invalid parameter value. | 823| 8300002 | Service connection failed. | 824| 8300003 | System internal error. | 825| 8300999 | Unknown error. | 826 827**Example** 828 829```ts 830let callback: () => void = () => { 831 console.log("on iccAccountInfoChange success"); 832} 833observer.on('iccAccountInfoChange', callback); 834// 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. 835observer.off('iccAccountInfoChange', callback); 836observer.off('iccAccountInfoChange'); 837``` 838 839 840## LockReason<sup>8+</sup> 841 842Enumerates SIM card lock types. 843 844**System capability**: SystemCapability.Telephony.StateRegistry 845 846| Name | Value | Description | 847| ----------- | ---- | ----------------- | 848| SIM_NONE | 0 | No lock. | 849| SIM_PIN | 1 | PIN lock. | 850| SIM_PUK | 2 | PUK lock. | 851| SIM_PN_PIN | 3 | Network PIN lock. | 852| SIM_PN_PUK | 4 | Network PUK lock. | 853| SIM_PU_PIN | 5 | Subnet PIN lock. | 854| SIM_PU_PUK | 6 | Subnet PUK lock. | 855| SIM_PP_PIN | 7 | Service provider PIN lock.| 856| SIM_PP_PUK | 8 | Service provider PUK lock.| 857| SIM_PC_PIN | 9 | Organization PIN lock. | 858| SIM_PC_PUK | 10 | Organization PUK lock. | 859| SIM_SIM_PIN | 11 | SIM PIN lock. | 860| SIM_SIM_PUK | 12 | SIM PUK lock. | 861 862 863## SimStateData<sup>7+</sup> 864 865Enumerates SIM card types and states. 866 867**System capability**: SystemCapability.Telephony.StateRegistry 868 869| Name | Type | Mandatory| Description | 870| ------------------- | ----------------------------------- | ---- | -------------------------------------------------------- | 871| type | [CardType](js-apis-sim.md#cardtype7) | Yes | SIM card type.| 872| state | [SimState](js-apis-sim.md#simstate) | Yes | SIM card state.| 873| reason<sup>8+</sup> | [LockReason](#lockreason8) | Yes | SIM card lock type. | 874 875 876## CallStateInfo<sup>11+</sup> 877 878Defines information about the call status. 879 880**System capability**: SystemCapability.Telephony.StateRegistry 881 882| Name | Type | Mandatory| Description | 883| ------------------- | -------------------------------------- | ---- | -------- | 884| state | [CallState](js-apis-call.md#callstate) | Yes | Call type.| 885| number | string | Yes | Phone number.| 886 887 888## DataConnectionStateInfo<sup>11+</sup> 889 890Defines information about the data connection status. 891 892**System capability**: SystemCapability.Telephony.StateRegistry 893 894| Name | Type | Mandatory| Description | 895| ------------------- | ---------------------------------------------------------------| ---- | ------------ | 896| state | [DataConnectState](js-apis-telephony-data.md#dataconnectstate) | Yes | Data connection status.| 897| network | [RatType](js-apis-radio.md#radiotechnology) | Yes | Network type. | 898 899 900## ObserverOptions<sup>11+</sup> 901 902Defines event subscription parameters. 903 904**System capability**: SystemCapability.Telephony.StateRegistry 905 906| Name | Type | Mandatory | Description | 907| ------------------- | ------------------| ---- | --------------------------------------- | 908| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 909