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 '@ohos.telephony.observer'; 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. | 41| 8300001 | Invalid parameter value. | 42| 8300002 | Operation failed. Cannot connect to service. | 43| 8300003 | System internal error. | 44| 8300999 | Unknown error code. | 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. | 81| 8300001 | Invalid parameter value. | 82| 8300002 | Operation failed. Cannot connect to service. | 83| 8300003 | System internal error. | 84| 8300999 | Unknown error code. | 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. | 124| 8300001 | Invalid parameter value. | 125| 8300002 | Operation failed. Cannot connect to service. | 126| 8300003 | System internal error. | 127| 8300999 | Unknown error code. | 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. | 163| 8300001 | Invalid parameter value. | 164| 8300002 | Operation failed. Cannot connect to service. | 165| 8300003 | System internal error. | 166| 8300999 | Unknown error code. | 167 168**Example** 169 170```ts 171import radio from '@ohos.telephony.radio'; 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. | 202| 8300001 | Invalid parameter value. | 203| 8300002 | Operation failed. Cannot connect to service. | 204| 8300003 | System internal error. | 205| 8300999 | Unknown error code. | 206 207**Example** 208 209```ts 210import radio from '@ohos.telephony.radio'; 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. | 247| 8300001 | Invalid parameter value. | 248| 8300002 | Operation failed. Cannot connect to service. | 249| 8300003 | System internal error. | 250| 8300999 | Unknown error code. | 251 252**Example** 253 254```ts 255import radio from '@ohos.telephony.radio'; 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**System capability**: SystemCapability.Telephony.StateRegistry 274 275**Parameters** 276 277| Name | Type | Mandatory| Description | 278| -------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 279| type | string | Yes | Call status change event. This field has a fixed value of **callStateChange**. | 280| callback | Callback\<[CallStateInfo](#callstateinfo11)\> | Yes | Callback used to return the result. For details, see [CallState](js-apis-call.md#callstate).<br>**number**: phone number.| 281 282**Error codes** 283 284For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 285 286| ID| Error Message | 287| -------- | -------------------------------------------- | 288| 401 | Parameter error. | 289| 8300001 | Invalid parameter value. | 290| 8300002 | Operation failed. Cannot connect to service. | 291| 8300003 | System internal error. | 292| 8300999 | Unknown error code. | 293 294**Example** 295 296```ts 297observer.on('callStateChange', (data: observer.CallStateInfo) => { 298 console.log("on callStateChange, data:" + JSON.stringify(data)); 299}); 300``` 301 302 303## observer.on('callStateChange') 304 305on(type: 'callStateChange', options: ObserverOptions, callback: Callback\<CallStateInfo\>): void 306 307Registers an observer for call status change events. This API uses an asynchronous callback to return the execution result. 308 309**System capability**: SystemCapability.Telephony.StateRegistry 310 311**Parameters** 312 313| Name | Type | Mandatory| Description | 314| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 315| type | string | Yes | Call status change event. This field has a fixed value of **callStateChange**. | 316| options | [ObserverOptions](#observeroptions11) | Yes | Event subscription parameters. | 317| callback | Callback\<[CallStateInfo](#callstateinfo11)\> | Yes | Callback used to return the result. For details, see [CallState](js-apis-call.md#callstate).<br>**number**: phone number.| 318 319**Error codes** 320 321For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 322 323| ID| Error Message | 324| -------- | -------------------------------------------- | 325| 401 | Parameter error. | 326| 8300001 | Invalid parameter value. | 327| 8300002 | Operation failed. Cannot connect to service. | 328| 8300003 | System internal error. | 329| 8300999 | Unknown error code. | 330 331**Example** 332 333```ts 334let options: observer.ObserverOptions = { 335 slotId: 0 336} 337observer.on('callStateChange', options, (data: observer.CallStateInfo) => { 338 console.log("on callStateChange, data:" + JSON.stringify(data)); 339}); 340``` 341 342 343## observer.off('callStateChange') 344 345off(type: 'callStateChange', callback?: Callback\<CallStateInfo\>): void 346 347Unregisters the observer for call status change events. This API uses an asynchronous callback to return the execution result. 348 349>**NOTE** 350> 351>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. 352 353**System capability**: SystemCapability.Telephony.StateRegistry 354 355**Parameters** 356 357| Name | Type | Mandatory| Description | 358| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 359| type | string | Yes | Call status change event. This field has a fixed value of **callStateChange**. | 360| callback | Callback\<[CallStateInfo](#callstateinfo11)\> | No | Callback used to return the result. For details, see [CallState](js-apis-call.md#callstate).<br>**number**: phone number.| 361 362**Error codes** 363 364For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 365 366| ID| Error Message | 367| -------- | -------------------------------------------- | 368| 401 | Parameter error. | 369| 8300001 | Invalid parameter value. | 370| 8300002 | Operation failed. Cannot connect to service. | 371| 8300003 | System internal error. | 372| 8300999 | Unknown error code. | 373 374**Example** 375 376```ts 377let callback: (data: observer.CallStateInfo) => void = (data: observer.CallStateInfo) => { 378 console.log("on callStateChange, data:" + JSON.stringify(data)); 379} 380observer.on('callStateChange', callback); 381// 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. 382observer.off('callStateChange', callback); 383observer.off('callStateChange'); 384``` 385 386 387## observer.on('cellularDataConnectionStateChange')<sup>7+</sup> 388 389on\(type: 'cellularDataConnectionStateChange', callback: Callback\<DataConnectionStateInfo\>\): void 390 391Registers an observer for connection status change events of the cellular data link. This API uses an asynchronous callback to return the result. 392 393**System capability**: SystemCapability.Telephony.StateRegistry 394 395**Parameters** 396 397| Name | Type | Mandatory| Description | 398| -------- | --------------------------------- | ---- | -------------------------------------------------------------------- | 399| type | string | Yes | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.| 400| 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).| 401 402**Error codes** 403 404For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 405 406| ID| Error Message | 407| -------- | -------------------------------------------- | 408| 401 | Parameter error. | 409| 8300001 | Invalid parameter value. | 410| 8300002 | Operation failed. Cannot connect to service. | 411| 8300003 | System internal error. | 412| 8300999 | Unknown error code. | 413 414**Example** 415 416```ts 417observer.on('cellularDataConnectionStateChange', (data: observer.DataConnectionStateInfo) => { 418 console.log("on cellularDataConnectionStateChange, data:" + JSON.stringify(data)); 419}); 420``` 421 422 423## observer.on('cellularDataConnectionStateChange')<sup>7+</sup> 424 425on\(type: 'cellularDataConnectionStateChange', options: ObserverOptions, callback: Callback\<DataConnectionStateInfo\>\): void 426 427Registers 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. 428 429**System capability**: SystemCapability.Telephony.StateRegistry 430 431**Parameters** 432 433| Name | Type | Mandatory| Description | 434| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 435| type | string | Yes | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.| 436| options | [ObserverOptions](#observeroptions11) | Yes | Event subscription parameters. | 437| 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).| 438 439**Error codes** 440 441For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 442 443| ID| Error Message | 444| -------- | -------------------------------------------- | 445| 401 | Parameter error. | 446| 8300001 | Invalid parameter value. | 447| 8300002 | Operation failed. Cannot connect to service. | 448| 8300003 | System internal error. | 449| 8300999 | Unknown error code. | 450 451**Example** 452 453```ts 454let options: observer.ObserverOptions = { 455 slotId: 0 456} 457observer.on('cellularDataConnectionStateChange', options, (data: observer.DataConnectionStateInfo) => { 458 console.log("on cellularDataConnectionStateChange, data:" + JSON.stringify(data)); 459}); 460``` 461 462 463## observer.off('cellularDataConnectionStateChange')<sup>7+</sup> 464 465off\(type: 'cellularDataConnectionStateChange', callback?: Callback\<DataConnectionStateInfo\>\): void 466 467Unregisters the observer for connection status change events of the cellular data link. This API uses an asynchronous callback to return the result. 468 469>**NOTE** 470> 471>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. 472 473**System capability**: SystemCapability.Telephony.StateRegistry 474 475**Parameters** 476 477| Name | Type | Mandatory| Description | 478| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 479| type | string | Yes | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.| 480| 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).| 481 482**Error codes** 483 484For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 485 486| ID| Error Message | 487| -------- | -------------------------------------------- | 488| 401 | Parameter error. | 489| 8300001 | Invalid parameter value. | 490| 8300002 | Operation failed. Cannot connect to service. | 491| 8300003 | System internal error. | 492| 8300999 | Unknown error code. | 493 494**Example** 495 496```ts 497let callback: (data: observer.DataConnectionStateInfo) => void = (data: observer.DataConnectionStateInfo) => { 498 console.log("on cellularDataConnectionStateChange, data:" + JSON.stringify(data)); 499} 500observer.on('cellularDataConnectionStateChange', callback); 501// 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. 502observer.off('cellularDataConnectionStateChange', callback); 503observer.off('cellularDataConnectionStateChange'); 504``` 505 506 507## observer.on('cellularDataFlowChange')<sup>7+</sup> 508 509on\(type: 'cellularDataFlowChange', callback: Callback\<DataFlowType\>\): void 510 511Registers 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. 512 513**System capability**: SystemCapability.Telephony.StateRegistry 514 515**Parameters** 516 517| Name | Type | Mandatory| Description | 518| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 519| type | string | Yes | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**. | 520| 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).| 521 522**Error codes** 523 524For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 525 526| ID| Error Message | 527| -------- | -------------------------------------------- | 528| 401 | Parameter error. | 529| 8300001 | Invalid parameter value. | 530| 8300002 | Operation failed. Cannot connect to service. | 531| 8300003 | System internal error. | 532| 8300999 | Unknown error code. | 533 534**Example** 535 536```ts 537import data from '@ohos.telephony.data'; 538 539observer.on('cellularDataFlowChange', (data: data.DataFlowType) => { 540 console.log("on cellularDataFlowChange, data:" + JSON.stringify(data)); 541}); 542``` 543 544 545## observer.on('cellularDataFlowChange')<sup>7+</sup> 546 547on\(type: 'cellularDataFlowChange', options: ObserverOptions, callback: Callback\<DataFlowType\>\): void 548 549Registers 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. 550 551**System capability**: SystemCapability.Telephony.StateRegistry 552 553**Parameters** 554 555| Name | Type | Mandatory| Description | 556| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 557| type | string | Yes | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**. | 558| options | [ObserverOptions](#observeroptions11) | Yes | Event subscription parameters. | 559| 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).| 560 561**Error codes** 562 563For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 564 565| ID| Error Message | 566| -------- | -------------------------------------------- | 567| 401 | Parameter error. | 568| 8300001 | Invalid parameter value. | 569| 8300002 | Operation failed. Cannot connect to service. | 570| 8300003 | System internal error. | 571| 8300999 | Unknown error code. | 572 573**Example** 574 575```ts 576import data from '@ohos.telephony.data'; 577 578let options: observer.ObserverOptions = { 579 slotId: 0 580} 581observer.on('cellularDataFlowChange', options, (data: data.DataFlowType) => { 582 console.log("on cellularDataFlowChange, data:" + JSON.stringify(data)); 583}); 584``` 585 586 587## observer.off('cellularDataFlowChange')<sup>7+</sup> 588 589off\(type: 'cellularDataFlowChange', callback?: Callback\<DataFlowType\>\): void 590 591Unregisters 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. 592 593>**NOTE** 594> 595>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. 596 597**System capability**: SystemCapability.Telephony.StateRegistry 598 599**Parameters** 600 601| Name | Type | Mandatory| Description | 602| -------- | ------------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 603| type | string | Yes | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**. | 604| 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).| 605 606**Error codes** 607 608For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 609 610| ID| Error Message | 611| -------- | -------------------------------------------- | 612| 401 | Parameter error. | 613| 8300001 | Invalid parameter value. | 614| 8300002 | Operation failed. Cannot connect to service. | 615| 8300003 | System internal error. | 616| 8300999 | Unknown error code. | 617 618**Example** 619 620```ts 621import data from '@ohos.telephony.data'; 622 623let callback: (data: data.DataFlowType) => void = (data: data.DataFlowType) => { 624 console.log("on cellularDataFlowChange, data:" + JSON.stringify(data)); 625} 626observer.on('cellularDataFlowChange', callback); 627// 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. 628observer.off('cellularDataFlowChange', callback); 629observer.off('cellularDataFlowChange'); 630``` 631 632 633## observer.on('simStateChange')<sup>7+</sup> 634 635on\(type: 'simStateChange', callback: Callback\<SimStateData\>\): void 636 637Registers an observer for SIM card status change events. This API uses an asynchronous callback to return the result. 638 639**System capability**: SystemCapability.Telephony.StateRegistry 640 641**Parameters** 642 643| Name | Type | Mandatory| Description | 644| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 645| type | string | Yes | SIM status change event. This field has a fixed value of **simStateChange**. | 646| callback | Callback\<[SimStateData](#simstatedata7)\> | Yes | Callback used to return the result.| 647 648**Error codes** 649 650For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 651 652| ID| Error Message | 653| -------- | -------------------------------------------- | 654| 401 | Parameter error. | 655| 8300001 | Invalid parameter value. | 656| 8300002 | Operation failed. Cannot connect to service. | 657| 8300003 | System internal error. | 658| 8300999 | Unknown error code. | 659 660**Example** 661 662```ts 663observer.on('simStateChange', (data: observer.SimStateData) => { 664 console.log("on simStateChange, data:" + JSON.stringify(data)); 665}); 666``` 667 668 669## observer.on('simStateChange')<sup>7+</sup> 670 671on\(type: 'simStateChange', options: ObserverOptions, callback: Callback\<SimStateData\>\): void 672 673Registers an observer for status change events of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 674 675**System capability**: SystemCapability.Telephony.StateRegistry 676 677**Parameters** 678 679| Name | Type | Mandatory| Description | 680| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 681| type | string | Yes | SIM status change event. This field has a fixed value of **simStateChange**. | 682| options | [ObserverOptions](#observeroptions11) | Yes | Event subscription parameters. | 683| callback | Callback\<[SimStateData](#simstatedata7)\> | Yes | Callback used to return the result.| 684 685**Error codes** 686 687For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 688 689| ID| Error Message | 690| -------- | -------------------------------------------- | 691| 401 | Parameter error. | 692| 8300001 | Invalid parameter value. | 693| 8300002 | Operation failed. Cannot connect to service. | 694| 8300003 | System internal error. | 695| 8300999 | Unknown error code. | 696 697**Example** 698 699```ts 700let options: observer.ObserverOptions = { 701 slotId: 0 702} 703observer.on('simStateChange', options, (data: observer.SimStateData) => { 704 console.log("on simStateChange, data:" + JSON.stringify(data)); 705}); 706``` 707 708 709## observer.off('simStateChange')<sup>7+</sup> 710 711off\(type: 'simStateChange', callback?: Callback\<SimStateData\>\): void 712 713Unregisters the observer for SIM card status change events. This API uses an asynchronous callback to return the result. 714 715>**NOTE** 716> 717>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. 718 719**System capability**: SystemCapability.Telephony.StateRegistry 720 721**Parameters** 722 723| Name | Type | Mandatory| Description | 724| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 725| type | string | Yes | SIM status change event. This field has a fixed value of **simStateChange**. | 726| callback | Callback\<[SimStateData](#simstatedata7)\> | No | Callback used to return the result.| 727 728**Error codes** 729 730For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 731 732| ID| Error Message | 733| -------- | -------------------------------------------- | 734| 401 | Parameter error. | 735| 8300001 | Invalid parameter value. | 736| 8300002 | Operation failed. Cannot connect to service. | 737| 8300003 | System internal error. | 738| 8300999 | Unknown error code. | 739 740**Example** 741 742```ts 743let callback: (data: observer.SimStateData) => void = (data: observer.SimStateData) => { 744 console.log("on simStateChange, data:" + JSON.stringify(data)); 745} 746observer.on('simStateChange', callback); 747// 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. 748observer.off('simStateChange', callback); 749observer.off('simStateChange'); 750``` 751 752## observer.on('iccAccountInfoChange')<sup>10+</sup> 753 754on\(type: 'iccAccountInfoChange', callback: Callback\<void\>\): void 755 756Registers an observer for account information change events of the SIM card. This API uses an asynchronous callback to return the result. 757 758**System capability**: SystemCapability.Telephony.StateRegistry 759 760**Parameters** 761 762| Name | Type | Mandatory| Description | 763| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 764| type | string | Yes | Account information change event. This field has a fixed value of **iccAccountInfoChange**. | 765| callback | Callback\<void\> | Yes | Callback used to return the result.| 766 767**Error codes** 768 769For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 770 771| ID| Error Message | 772| -------- | -------------------------------------------- | 773| 401 | Parameter error. | 774| 8300001 | Invalid parameter value. | 775| 8300002 | Operation failed. Cannot connect to service. | 776| 8300003 | System internal error. | 777| 8300999 | Unknown error code. | 778 779**Example** 780 781```ts 782observer.on('iccAccountInfoChange', () => { 783 console.log("on iccAccountInfoChange success"); 784}); 785``` 786 787 788## observer.off('iccAccountInfoChange')<sup>10+</sup> 789 790off\(type: 'iccAccountInfoChange', callback?: Callback\<void\>\): void 791 792Unregisters the observer for account information change events of the SIM card. This API uses an asynchronous callback to return the result. 793 794>**NOTE** 795> 796>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. 797 798**System capability**: SystemCapability.Telephony.StateRegistry 799 800**Parameters** 801 802| Name | Type | Mandatory| Description | 803| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 804| type | string | Yes | Account information change event. This field has a fixed value of **iccAccountInfoChange**. | 805| callback | Callback\<void\> | No | Callback used to return the result.| 806 807**Error codes** 808 809For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 810 811| ID| Error Message | 812| -------- | -------------------------------------------- | 813| 401 | Parameter error. | 814| 8300001 | Invalid parameter value. | 815| 8300002 | Operation failed. Cannot connect to service. | 816| 8300003 | System internal error. | 817| 8300999 | Unknown error code. | 818 819**Example** 820 821```ts 822let callback: () => void = () => { 823 console.log("on iccAccountInfoChange success"); 824} 825observer.on('iccAccountInfoChange', callback); 826// 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. 827observer.off('iccAccountInfoChange', callback); 828observer.off('iccAccountInfoChange'); 829``` 830 831 832## LockReason<sup>8+</sup> 833 834Enumerates SIM card lock types. 835 836**System capability**: SystemCapability.Telephony.StateRegistry 837 838| Name | Value | Description | 839| ----------- | ---- | ----------------- | 840| SIM_NONE | 0 | No lock. | 841| SIM_PIN | 1 | PIN lock. | 842| SIM_PUK | 2 | PUK lock. | 843| SIM_PN_PIN | 3 | Network PIN lock. | 844| SIM_PN_PUK | 4 | Network PUK lock. | 845| SIM_PU_PIN | 5 | Subnet PIN lock. | 846| SIM_PU_PUK | 6 | Subnet PUK lock. | 847| SIM_PP_PIN | 7 | Service provider PIN lock.| 848| SIM_PP_PUK | 8 | Service provider PUK lock.| 849| SIM_PC_PIN | 9 | Organization PIN lock. | 850| SIM_PC_PUK | 10 | Organization PUK lock. | 851| SIM_SIM_PIN | 11 | SIM PIN lock. | 852| SIM_SIM_PUK | 12 | SIM PUK lock. | 853 854 855## SimStateData<sup>7+</sup> 856 857Enumerates SIM card types and states. 858 859**System capability**: SystemCapability.Telephony.StateRegistry 860 861| Name | Type | Mandatory| Description | 862| ------------------- | ----------------------------------- | ---- | -------------------------------------------------------- | 863| type | [CardType](js-apis-sim.md#cardtype7) | Yes | SIM card type.| 864| state | [SimState](js-apis-sim.md#simstate) | Yes | SIM card state.| 865| reason<sup>8+</sup> | [LockReason](#lockreason8) | Yes | SIM card lock type. | 866 867 868## CallStateInfo<sup>11+</sup> 869 870Defines information about the call status. 871 872**System capability**: SystemCapability.Telephony.StateRegistry 873 874| Name | Type | Mandatory| Description | 875| ------------------- | -------------------------------------- | ---- | -------- | 876| state | [CallState](js-apis-call.md#callstate) | Yes | Call type.| 877| number | string | Yes | Phone number.| 878 879 880## DataConnectionStateInfo<sup>11+</sup> 881 882Defines information about the data connection status. 883 884**System capability**: SystemCapability.Telephony.StateRegistry 885 886| Name | Type | Mandatory| Description | 887| ------------------- | ---------------------------------------------------------------| ---- | ------------ | 888| state | [DataConnectState](js-apis-telephony-data.md#dataconnectstate) | Yes | Data connection status.| 889| network | [RatType](js-apis-radio.md#radiotechnology) | Yes | Network type. | 890 891 892## ObserverOptions<sup>11+</sup> 893 894Defines event subscription parameters. 895 896**System capability**: SystemCapability.Telephony.StateRegistry 897 898| Name | Type | Mandatory | Description | 899| ------------------- | ------------------| ---- | --------------------------------------- | 900| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 901