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 following error codes, see [Telephony Error Codes](../../reference/errorcodes/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: { slotId: number }, 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| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 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 following error codes, see [Telephony Error Codes](../../reference/errorcodes/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 89class SlotId { 90 slotId: number = 0 91} 92let id: SlotId = {slotId: 0} 93observer.on('networkStateChange', id, (data: observer.NetworkState) => { 94 console.log("on networkStateChange, data:" + JSON.stringify(data)); 95}); 96``` 97 98 99## observer.off('networkStateChange') 100 101off\(type: \'networkStateChange\', callback?: Callback\<NetworkState\>\): void 102 103Unregisters the observer for network status change events. This API uses an asynchronous callback to return the execution result. 104 105>**NOTE** 106> 107>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. 108 109**System capability**: SystemCapability.Telephony.StateRegistry 110 111**Parameters** 112 113| Name | Type | Mandatory| Description | 114| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | 115| type | string | Yes | Network status change event. This field has a fixed value of **networkStateChange**. | 116| callback | Callback\<[NetworkState](js-apis-radio.md#networkstate)\> | No | Callback used to return the result. For details, see [NetworkState](js-apis-radio.md#networkstate).| 117 118**Error codes** 119 120For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 121 122| ID| Error Message | 123| -------- | -------------------------------------------- | 124| 401 | Parameter error. | 125| 8300001 | Invalid parameter value. | 126| 8300002 | Operation failed. Cannot connect to service. | 127| 8300003 | System internal error. | 128| 8300999 | Unknown error code. | 129 130**Example** 131 132```ts 133let callback: (data: observer.NetworkState) => void = (data: observer.NetworkState) => { 134 console.log("on networkStateChange, data:" + JSON.stringify(data)); 135} 136observer.on('networkStateChange', callback); 137// 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. 138observer.off('networkStateChange', callback); 139observer.off('networkStateChange'); 140``` 141 142## observer.on('signalInfoChange') 143 144on\(type: \'signalInfoChange\', callback: Callback\<Array\<SignalInformation\>\>): void 145 146Registers an observer for signal status change events. This API uses an asynchronous callback to return the execution result. 147 148**System capability**: SystemCapability.Telephony.StateRegistry 149 150**Parameters** 151 152| Name | Type | Mandatory| Description | 153| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 154| type | string | Yes | Signal status change event. This field has a fixed value of **signalInfoChange**. | 155| 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).| 156 157**Error codes** 158 159For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 160 161| ID| Error Message | 162| -------- | -------------------------------------------- | 163| 401 | Parameter error. | 164| 8300001 | Invalid parameter value. | 165| 8300002 | Operation failed. Cannot connect to service. | 166| 8300003 | System internal error. | 167| 8300999 | Unknown error code. | 168 169**Example** 170 171```ts 172import radio from '@ohos.telephony.radio'; 173 174observer.on('signalInfoChange', (data: Array<radio.SignalInformation>) => { 175 console.log("on signalInfoChange, data:" + JSON.stringify(data)); 176}); 177``` 178 179 180## observer.on('signalInfoChange') 181 182on\(type: \'signalInfoChange\', options: { slotId: number }, callback: Callback\<Array\<SignalInformation\>\>): void 183 184Registers 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. 185 186**System capability**: SystemCapability.Telephony.StateRegistry 187 188**Parameters** 189 190| Name | Type | Mandatory| Description | 191| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 192| type | string | Yes | Signal status change event. This field has a fixed value of **signalInfoChange**. | 193| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 194| 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).| 195 196**Error codes** 197 198For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 199 200| ID| Error Message | 201| -------- | -------------------------------------------- | 202| 401 | Parameter error. | 203| 8300001 | Invalid parameter value. | 204| 8300002 | Operation failed. Cannot connect to service. | 205| 8300003 | System internal error. | 206| 8300999 | Unknown error code. | 207 208**Example** 209 210```ts 211import radio from '@ohos.telephony.radio'; 212 213class SlotId { 214 slotId: number = 0 215} 216let id: SlotId = {slotId: 0} 217observer.on('signalInfoChange', id, (data: Array<radio.SignalInformation>) => { 218 console.log("on signalInfoChange, data:" + JSON.stringify(data)); 219}); 220``` 221 222 223## observer.off('signalInfoChange') 224 225off\(type: \'signalInfoChange\', callback?: Callback\<Array\<SignalInformation\>\>): void 226 227Unregisters the observer for signal status change events. This API uses an asynchronous callback to return the execution result. 228 229>**NOTE** 230> 231>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. 232 233**System capability**: SystemCapability.Telephony.StateRegistry 234 235**Parameters** 236 237| Name | Type | Mandatory| Description | 238| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 239| type | string | Yes | Signal status change event. This field has a fixed value of **signalInfoChange**. | 240| 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).| 241 242**Error codes** 243 244For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 245 246| ID| Error Message | 247| -------- | -------------------------------------------- | 248| 401 | Parameter error. | 249| 8300001 | Invalid parameter value. | 250| 8300002 | Operation failed. Cannot connect to service. | 251| 8300003 | System internal error. | 252| 8300999 | Unknown error code. | 253 254**Example** 255 256```ts 257import radio from '@ohos.telephony.radio'; 258 259let callback: (data: Array<radio.SignalInformation>) => void = (data: Array<radio.SignalInformation>) => { 260 console.log("on signalInfoChange, data:" + JSON.stringify(data)); 261} 262observer.on('signalInfoChange', callback); 263// 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. 264observer.off('signalInfoChange', callback); 265observer.off('signalInfoChange'); 266``` 267 268## observer.on('cellInfoChange')<sup>8+</sup> 269 270on\(type: \'cellInfoChange\', callback: Callback\<Array\<CellInformation\>\>\): void 271 272Registers an observer for cell information change events. This API uses an asynchronous callback to return the result. 273 274**System API**: This is a system API. 275 276**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 277 278**System capability**: SystemCapability.Telephony.StateRegistry 279 280**Parameters** 281 282| Name | Type | Mandatory| Description | 283| -------- | --------------------------------------------------------- | ---- |------------------------------------------| 284| type | string | Yes | Cell information change event. This field has a fixed value of **cellInfoChange**.| 285| callback | Callback\<Array\<[CellInformation](js-apis-radio.md#cellinformation8)\>\> | Yes | Callback used to return the result. | 286 287**Error codes** 288 289For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 290 291| ID| Error Message | 292| -------- | -------------------------------------------- | 293| 201 | Permission denied. | 294| 202 | Non-system applications use system APIs. | 295| 401 | Parameter error. | 296| 8300001 | Invalid parameter value. | 297| 8300002 | Operation failed. Cannot connect to service. | 298| 8300003 | System internal error. | 299| 8300999 | Unknown error code. | 300 301**Example** 302 303```ts 304import radio from '@ohos.telephony.radio'; 305 306observer.on('cellInfoChange', (data: Array<radio.CellInformation>) => { 307 console.log("on cellInfoChange, data:" + JSON.stringify(data)); 308}); 309``` 310 311 312## observer.on('cellInfoChange')<sup>8+</sup> 313 314on\(type: \'cellInfoChange\', options: { slotId: number }, callback: Callback\<Array\<CellInformation\>\>\): void 315 316Registers 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. 317 318**System API**: This is a system API. 319 320**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 321 322**System capability**: SystemCapability.Telephony.StateRegistry 323 324**Parameters** 325 326| Name| Type | Mandatory| Description | 327| ------ |--------------------------------------------------| ---- |--------------------------------------------| 328| type | string | Yes | Cell information change event. This field has a fixed value of **cellInfoChange**.| 329| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 330| callback | Callback\<Array\<[CellInformation](js-apis-radio.md#cellinformation8)\>\> | Yes | Callback used to return the result. | 331 332**Error codes** 333 334For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 335 336| ID| Error Message | 337| -------- | -------------------------------------------- | 338| 201 | Permission denied. | 339| 202 | Non-system applications use system APIs. | 340| 401 | Parameter error. | 341| 8300001 | Invalid parameter value. | 342| 8300002 | Operation failed. Cannot connect to service. | 343| 8300003 | System internal error. | 344| 8300999 | Unknown error code. | 345 346**Example** 347 348```ts 349import radio from '@ohos.telephony.radio'; 350 351class SlotId { 352 slotId: number = 0 353} 354let id: SlotId = {slotId: 0} 355observer.on('cellInfoChange', id, (data: Array<radio.CellInformation>) => { 356 console.log("on cellInfoChange, data:" + JSON.stringify(data)); 357}); 358``` 359 360 361## observer.off('cellInfoChange')<sup>8+</sup> 362 363off\(type: \'cellInfoChange\', callback?: Callback\<Array\<CellInformation\>\>\): void 364 365Unregisters the observer for cell information change events. This API uses an asynchronous callback to return the result. 366 367>**NOTE** 368> 369>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. 370 371**System API**: This is a system API. 372 373**System capability**: SystemCapability.Telephony.StateRegistry 374 375**Parameters** 376 377| Name | Type | Mandatory| Description | 378| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | 379| type | string | Yes | Cell information change event. This field has a fixed value of **cellInfoChange**. | 380| callback | Callback\<Array\<[CellInformation](js-apis-radio.md#cellinformation8)\>\> | No | Callback used to return the result.| 381 382**Error codes** 383 384For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 385 386| ID| Error Message | 387| -------- | -------------------------------------------- | 388| 202 | Non-system applications use system APIs. | 389| 401 | Parameter error. | 390| 8300001 | Invalid parameter value. | 391| 8300002 | Operation failed. Cannot connect to service. | 392| 8300003 | System internal error. | 393| 8300999 | Unknown error code. | 394 395**Example** 396 397```ts 398import radio from '@ohos.telephony.radio'; 399 400let callback: (data: Array<radio.CellInformation>) => void = (data: Array<radio.CellInformation>) => { 401 console.log("on cellInfoChange, data:" + JSON.stringify(data)); 402} 403observer.on('cellInfoChange', callback); 404// 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. 405observer.off('cellInfoChange', callback); 406observer.off('cellInfoChange'); 407``` 408 409## observer.on('callStateChange') 410 411on(type: 'callStateChange', callback: Callback\<{ state: CallState, number: string }\>): void 412 413Registers an observer for call status change events. This API uses an asynchronous callback to return the execution result. 414 415**System capability**: SystemCapability.Telephony.StateRegistry 416 417**Parameters** 418 419| Name | Type | Mandatory| Description | 420| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 421| type | string | Yes | Call status change event. This field has a fixed value of **callStateChange**. | 422| callback | Callback\<{ state: [CallState](js-apis-call.md#callstate), number: string }\> | Yes | Callback used to return the result. For details, see [CallState](js-apis-call.md#callstate).<br>**number**: phone number.| 423 424**Error codes** 425 426For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 427 428| ID| Error Message | 429| -------- | -------------------------------------------- | 430| 401 | Parameter error. | 431| 8300001 | Invalid parameter value. | 432| 8300002 | Operation failed. Cannot connect to service. | 433| 8300003 | System internal error. | 434| 8300999 | Unknown error code. | 435 436**Example** 437 438```ts 439import call from '@ohos.telephony.call'; 440 441class Value { 442 state: call.CallState = call.CallState.CALL_STATE_UNKNOWN 443 number: string = "" 444} 445observer.on('callStateChange', (value: Value) => { 446 console.log("on callStateChange, state:" + value.state + ", number:" + value.number); 447}); 448``` 449 450 451## observer.on('callStateChange') 452 453on(type: 'callStateChange', options: { slotId: number }, callback: Callback<{ state:CallState, number: string }>): void 454 455Registers an observer for call status change events. This API uses an asynchronous callback to return the execution result. 456 457**System capability**: SystemCapability.Telephony.StateRegistry 458 459**Parameters** 460 461| Name | Type | Mandatory| Description | 462| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 463| type | string | Yes | Call status change event. This field has a fixed value of **callStateChange**. | 464| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 465| callback | Callback\<{ state: [CallState](js-apis-call.md#callstate), number: string }\> | Yes | Callback used to return the result. For details, see [CallState](js-apis-call.md#callstate).<br>**number**: phone number.| 466 467**Error codes** 468 469For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 470 471| ID| Error Message | 472| -------- | -------------------------------------------- | 473| 401 | Parameter error. | 474| 8300001 | Invalid parameter value. | 475| 8300002 | Operation failed. Cannot connect to service. | 476| 8300003 | System internal error. | 477| 8300999 | Unknown error code. | 478 479**Example** 480 481```ts 482import call from '@ohos.telephony.call'; 483 484class Value { 485 state: call.CallState = call.CallState.CALL_STATE_UNKNOWN 486 number: string = "" 487} 488class SlotId { 489 slotId: number = 0 490} 491let id: SlotId = {slotId: 0} 492observer.on('callStateChange', id, (value: Value) => { 493 console.log("on callStateChange, state:" + value.state + ", number:" + value.number); 494}); 495``` 496 497 498## observer.off('callStateChange') 499 500off(type: 'callStateChange', callback?: Callback<{ state: CallState, number: string }>): void 501 502Unregisters the observer for call status change events. This API uses an asynchronous callback to return the execution result. 503 504>**NOTE** 505> 506>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. 507 508**System capability**: SystemCapability.Telephony.StateRegistry 509 510**Parameters** 511 512| Name | Type | Mandatory| Description | 513| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 514| type | string | Yes | Call status change event. This field has a fixed value of **callStateChange**. | 515| callback | Callback\<{ state: [CallState](js-apis-call.md#callstate), number: string }\> | No | Callback used to return the result. For details, see [CallState](js-apis-call.md#callstate).<br>**number**: phone number.| 516 517**Error codes** 518 519For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 520 521| ID| Error Message | 522| -------- | -------------------------------------------- | 523| 401 | Parameter error. | 524| 8300001 | Invalid parameter value. | 525| 8300002 | Operation failed. Cannot connect to service. | 526| 8300003 | System internal error. | 527| 8300999 | Unknown error code. | 528 529**Example** 530 531```ts 532import call from '@ohos.telephony.call'; 533 534class Value { 535 state: call.CallState = call.CallState.CALL_STATE_UNKNOWN 536 number: string = "" 537} 538let callback: (value: Value) => void = (value: Value) => { 539 console.log("on callStateChange, state:" + value.state + ", number:" + value.number); 540} 541observer.on('callStateChange', callback); 542// 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. 543observer.off('callStateChange', callback); 544observer.off('callStateChange'); 545``` 546 547 548## observer.on('cellularDataConnectionStateChange')<sup>7+</sup> 549 550on\(type: 'cellularDataConnectionStateChange', callback: Callback\<{ state: DataConnectState, network: RatType}\>\): void 551 552Registers an observer for connection status change events of the cellular data link. This API uses an asynchronous callback to return the result. 553 554**System capability**: SystemCapability.Telephony.StateRegistry 555 556**Parameters** 557 558| Name | Type | Mandatory| Description | 559| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 560| type | string | Yes | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.| 561| callback | Callback\<{ state: [DataConnectState](js-apis-telephony-data.md#dataconnectstate), network: [RatType](js-apis-radio.md#radiotechnology) }\> | Yes | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).| 562 563**Error codes** 564 565For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 566 567| ID| Error Message | 568| -------- | -------------------------------------------- | 569| 401 | Parameter error. | 570| 8300001 | Invalid parameter value. | 571| 8300002 | Operation failed. Cannot connect to service. | 572| 8300003 | System internal error. | 573| 8300999 | Unknown error code. | 574 575**Example** 576 577```ts 578import data from '@ohos.telephony.data'; 579import radio from '@ohos.telephony.radio'; 580 581class Value { 582 state: data.DataConnectState = data.DataConnectState.DATA_STATE_UNKNOWN 583 network: radio.RadioTechnology = radio.RadioTechnology.RADIO_TECHNOLOGY_UNKNOWN 584} 585observer.on('cellularDataConnectionStateChange', (value: Value) => { 586 console.log("on cellularDataConnectionStateChange, state:" + value.state + ", network:" + value.network); 587}); 588``` 589 590 591## observer.on('cellularDataConnectionStateChange')<sup>7+</sup> 592 593on\(type: 'cellularDataConnectionStateChange', options: { slotId: number }, callback: Callback\<{ state: DataConnectState, network: RatType }\>\): void 594 595Registers 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. 596 597**System capability**: SystemCapability.Telephony.StateRegistry 598 599**Parameters** 600 601| Name | Type | Mandatory| Description | 602| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 603| type | string | Yes | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.| 604| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 605| callback | Callback\<{ state: [DataConnectState](js-apis-telephony-data.md#dataconnectstate), network: [RatType](js-apis-radio.md#radiotechnology) }\> | Yes | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).| 606 607**Error codes** 608 609For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 610 611| ID| Error Message | 612| -------- | -------------------------------------------- | 613| 401 | Parameter error. | 614| 8300001 | Invalid parameter value. | 615| 8300002 | Operation failed. Cannot connect to service. | 616| 8300003 | System internal error. | 617| 8300999 | Unknown error code. | 618 619**Example** 620 621```ts 622import data from '@ohos.telephony.data'; 623import radio from '@ohos.telephony.radio'; 624 625class Value { 626 state: data.DataConnectState = data.DataConnectState.DATA_STATE_UNKNOWN 627 network: radio.RadioTechnology = radio.RadioTechnology.RADIO_TECHNOLOGY_UNKNOWN 628} 629class SlotId { 630 slotId: number = 0 631} 632let id: SlotId = {slotId: 0} 633observer.on('cellularDataConnectionStateChange', id, (value: Value) => { 634 console.log("on cellularDataConnectionStateChange, state:" + value.state + ", network:" + value.network); 635}); 636``` 637 638 639## observer.off('cellularDataConnectionStateChange')<sup>7+</sup> 640 641off\(type: 'cellularDataConnectionStateChange', callback?: Callback\<{ state: DataConnectState, network: RatType}\>\): void 642 643Unregisters the observer for connection status change events of the cellular data link. This API uses an asynchronous callback to return the result. 644 645>**NOTE** 646> 647>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. 648 649**System capability**: SystemCapability.Telephony.StateRegistry 650 651**Parameters** 652 653| Name | Type | Mandatory| Description | 654| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 655| type | string | Yes | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.| 656| callback | Callback\<{ state: [DataConnectState](js-apis-telephony-data.md#dataconnectstate), network: [RatType](js-apis-radio.md#radiotechnology) }\> | No | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).| 657 658**Error codes** 659 660For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 661 662| ID| Error Message | 663| -------- | -------------------------------------------- | 664| 401 | Parameter error. | 665| 8300001 | Invalid parameter value. | 666| 8300002 | Operation failed. Cannot connect to service. | 667| 8300003 | System internal error. | 668| 8300999 | Unknown error code. | 669 670**Example** 671 672```ts 673import data from '@ohos.telephony.data'; 674import radio from '@ohos.telephony.radio'; 675 676class Value { 677 state: data.DataConnectState = data.DataConnectState.DATA_STATE_UNKNOWN 678 network: radio.RadioTechnology = radio.RadioTechnology.RADIO_TECHNOLOGY_UNKNOWN 679} 680let callback: (value: Value) => void = (value: Value) => { 681 console.log("on cellularDataConnectionStateChange, state:" + value.state + ", network:" + value.network); 682} 683observer.on('cellularDataConnectionStateChange', callback); 684// 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. 685observer.off('cellularDataConnectionStateChange', callback); 686observer.off('cellularDataConnectionStateChange'); 687``` 688 689 690## observer.on('cellularDataFlowChange')<sup>7+</sup> 691 692on\(type: 'cellularDataFlowChange', callback: Callback\<DataFlowType\>\): void 693 694Registers 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. 695 696**System capability**: SystemCapability.Telephony.StateRegistry 697 698**Parameters** 699 700| Name | Type | Mandatory| Description | 701| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 702| type | string | Yes | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**. | 703| 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).| 704 705**Error codes** 706 707For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 708 709| ID| Error Message | 710| -------- | -------------------------------------------- | 711| 401 | Parameter error. | 712| 8300001 | Invalid parameter value. | 713| 8300002 | Operation failed. Cannot connect to service. | 714| 8300003 | System internal error. | 715| 8300999 | Unknown error code. | 716 717**Example** 718 719```ts 720import data from '@ohos.telephony.data'; 721 722observer.on('cellularDataFlowChange', (data: data.DataFlowType) => { 723 console.log("on cellularDataFlowChange, data:" + JSON.stringify(data)); 724}); 725``` 726 727 728## observer.on('cellularDataFlowChange')<sup>7+</sup> 729 730on\(type: 'cellularDataFlowChange', options: { slotId: number }, callback: Callback\<DataFlowType\>\): void 731 732Registers 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. 733 734**System capability**: SystemCapability.Telephony.StateRegistry 735 736**Parameters** 737 738| Name | Type | Mandatory| Description | 739| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 740| type | string | Yes | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**. | 741| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 742| 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).| 743 744**Error codes** 745 746For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 747 748| ID| Error Message | 749| -------- | -------------------------------------------- | 750| 401 | Parameter error. | 751| 8300001 | Invalid parameter value. | 752| 8300002 | Operation failed. Cannot connect to service. | 753| 8300003 | System internal error. | 754| 8300999 | Unknown error code. | 755 756**Example** 757 758```ts 759import data from '@ohos.telephony.data'; 760 761class SlotId { 762 slotId: number = 0 763} 764let id: SlotId = {slotId: 0} 765observer.on('cellularDataFlowChange', id, (data: data.DataFlowType) => { 766 console.log("on cellularDataFlowChange, data:" + JSON.stringify(data)); 767}); 768``` 769 770 771## observer.off('cellularDataFlowChange')<sup>7+</sup> 772 773off\(type: 'cellularDataFlowChange', callback?: Callback\<DataFlowType\>\): void 774 775Unregisters 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. 776 777>**NOTE** 778> 779>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. 780 781**System capability**: SystemCapability.Telephony.StateRegistry 782 783**Parameters** 784 785| Name | Type | Mandatory| Description | 786| -------- | ------------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 787| type | string | Yes | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**. | 788| 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).| 789 790**Error codes** 791 792For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 793 794| ID| Error Message | 795| -------- | -------------------------------------------- | 796| 401 | Parameter error. | 797| 8300001 | Invalid parameter value. | 798| 8300002 | Operation failed. Cannot connect to service. | 799| 8300003 | System internal error. | 800| 8300999 | Unknown error code. | 801 802**Example** 803 804```ts 805import data from '@ohos.telephony.data'; 806 807let callback: (data: data.DataFlowType) => void = (data: data.DataFlowType) => { 808 console.log("on cellularDataFlowChange, data:" + JSON.stringify(data)); 809} 810observer.on('cellularDataFlowChange', callback); 811// 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. 812observer.off('cellularDataFlowChange', callback); 813observer.off('cellularDataFlowChange'); 814``` 815 816 817## observer.on('simStateChange')<sup>7+</sup> 818 819on\(type: 'simStateChange', callback: Callback\<SimStateData\>\): void 820 821Registers an observer for SIM card status change events. This API uses an asynchronous callback to return the result. 822 823**System capability**: SystemCapability.Telephony.StateRegistry 824 825**Parameters** 826 827| Name | Type | Mandatory| Description | 828| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 829| type | string | Yes | SIM status change event. This field has a fixed value of **simStateChange**. | 830| callback | Callback\<[SimStateData](#simstatedata7)\> | Yes | Callback used to return the result.| 831 832**Error codes** 833 834For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 835 836| ID| Error Message | 837| -------- | -------------------------------------------- | 838| 401 | Parameter error. | 839| 8300001 | Invalid parameter value. | 840| 8300002 | Operation failed. Cannot connect to service. | 841| 8300003 | System internal error. | 842| 8300999 | Unknown error code. | 843 844**Example** 845 846```ts 847observer.on('simStateChange', (data: observer.SimStateData) => { 848 console.log("on simStateChange, data:" + JSON.stringify(data)); 849}); 850``` 851 852 853## observer.on('simStateChange')<sup>7+</sup> 854 855on\(type: 'simStateChange', options: { slotId: number }, callback: Callback\<SimStateData\>\): void 856 857Registers an observer for status change events of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 858 859**System capability**: SystemCapability.Telephony.StateRegistry 860 861**Parameters** 862 863| Name | Type | Mandatory| Description | 864| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 865| type | string | Yes | SIM status change event. This field has a fixed value of **simStateChange**. | 866| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 867| callback | Callback\<[SimStateData](#simstatedata7)\> | Yes | Callback used to return the result.| 868 869**Error codes** 870 871For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 872 873| ID| Error Message | 874| -------- | -------------------------------------------- | 875| 401 | Parameter error. | 876| 8300001 | Invalid parameter value. | 877| 8300002 | Operation failed. Cannot connect to service. | 878| 8300003 | System internal error. | 879| 8300999 | Unknown error code. | 880 881**Example** 882 883```ts 884class SlotId { 885 slotId: number = 0 886} 887let id: SlotId = {slotId: 0} 888observer.on('simStateChange', id, (data: observer.SimStateData) => { 889 console.log("on simStateChange, data:" + JSON.stringify(data)); 890}); 891``` 892 893 894## observer.off('simStateChange')<sup>7+</sup> 895 896off\(type: 'simStateChange', callback?: Callback\<SimStateData\>\): void 897 898Unregisters the observer for SIM card status change events. This API uses an asynchronous callback to return the result. 899 900>**NOTE** 901> 902>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. 903 904**System capability**: SystemCapability.Telephony.StateRegistry 905 906**Parameters** 907 908| Name | Type | Mandatory| Description | 909| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 910| type | string | Yes | SIM status change event. This field has a fixed value of **simStateChange**. | 911| callback | Callback\<[SimStateData](#simstatedata7)\> | No | Callback used to return the result.| 912 913**Error codes** 914 915For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 916 917| ID| Error Message | 918| -------- | -------------------------------------------- | 919| 401 | Parameter error. | 920| 8300001 | Invalid parameter value. | 921| 8300002 | Operation failed. Cannot connect to service. | 922| 8300003 | System internal error. | 923| 8300999 | Unknown error code. | 924 925**Example** 926 927```ts 928let callback: (data: observer.SimStateData) => void = (data: observer.SimStateData) => { 929 console.log("on simStateChange, data:" + JSON.stringify(data)); 930} 931observer.on('simStateChange', callback); 932// 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. 933observer.off('simStateChange', callback); 934observer.off('simStateChange'); 935``` 936 937## observer.on('iccAccountInfoChange')<sup>10+</sup> 938 939on\(type: 'iccAccountInfoChange', callback: Callback\<void\>\): void 940 941Registers an observer for account information change events of the SIM card. This API uses an asynchronous callback to return the result. 942 943**System capability**: SystemCapability.Telephony.StateRegistry 944 945**Parameters** 946 947| Name | Type | Mandatory| Description | 948| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 949| type | string | Yes | Account information change event. This field has a fixed value of **iccAccountInfoChange**. | 950| callback | Callback\<void\> | Yes | Callback used to return the result.| 951 952**Error codes** 953 954For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 955 956| ID| Error Message | 957| -------- | -------------------------------------------- | 958| 401 | Parameter error. | 959| 8300001 | Invalid parameter value. | 960| 8300002 | Operation failed. Cannot connect to service. | 961| 8300003 | System internal error. | 962| 8300999 | Unknown error code. | 963 964**Example** 965 966```ts 967observer.on('iccAccountInfoChange', () => { 968 console.log("on iccAccountInfoChange success"); 969}); 970``` 971 972 973## observer.off('iccAccountInfoChange')<sup>10+</sup> 974 975off\(type: 'iccAccountInfoChange', callback?: Callback\<void\>\): void 976 977Unregisters the observer for account information change events of the SIM card. This API uses an asynchronous callback to return the result. 978 979>**NOTE** 980> 981>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. 982 983**System capability**: SystemCapability.Telephony.StateRegistry 984 985**Parameters** 986 987| Name | Type | Mandatory| Description | 988| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 989| type | string | Yes | Account information change event. This field has a fixed value of **iccAccountInfoChange**. | 990| callback | Callback\<void\> | No | Callback used to return the result.| 991 992**Error codes** 993 994For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 995 996| ID| Error Message | 997| -------- | -------------------------------------------- | 998| 401 | Parameter error. | 999| 8300001 | Invalid parameter value. | 1000| 8300002 | Operation failed. Cannot connect to service. | 1001| 8300003 | System internal error. | 1002| 8300999 | Unknown error code. | 1003 1004**Example** 1005 1006```ts 1007let callback: () => void = () => { 1008 console.log("on iccAccountInfoChange success"); 1009} 1010observer.on('iccAccountInfoChange', callback); 1011// 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. 1012observer.off('iccAccountInfoChange', callback); 1013observer.off('iccAccountInfoChange'); 1014``` 1015 1016 1017## LockReason<sup>8+</sup> 1018 1019Enumerates SIM card lock types. 1020 1021**System capability**: SystemCapability.Telephony.StateRegistry 1022 1023| Name | Value | Description | 1024| ----------- | ---- | ----------------- | 1025| SIM_NONE | 0 | No lock. | 1026| SIM_PIN | 1 | PIN lock. | 1027| SIM_PUK | 2 | PUK lock. | 1028| SIM_PN_PIN | 3 | Network PIN lock. | 1029| SIM_PN_PUK | 4 | Network PUK lock. | 1030| SIM_PU_PIN | 5 | Subnet PIN lock. | 1031| SIM_PU_PUK | 6 | Subnet PUK lock. | 1032| SIM_PP_PIN | 7 | Service provider PIN lock.| 1033| SIM_PP_PUK | 8 | Service provider PUK lock.| 1034| SIM_PC_PIN | 9 | Organization PIN lock. | 1035| SIM_PC_PUK | 10 | Organization PUK lock. | 1036| SIM_SIM_PIN | 11 | SIM PIN lock. | 1037| SIM_SIM_PUK | 12 | SIM PUK lock. | 1038 1039 1040## SimStateData<sup>7+</sup> 1041 1042Enumerates SIM card types and states. 1043 1044**System capability**: SystemCapability.Telephony.StateRegistry 1045 1046| Name | Type | Mandatory| Description | 1047| ------------------- | ----------------------------------- | ---- | -------------------------------------------------------- | 1048| type | [CardType](js-apis-sim.md#cardtype7) | Yes | SIM card type.| 1049| state | [SimState](js-apis-sim.md#simstate) | Yes | SIM card state.| 1050| reason<sup>8+</sup> | [LockReason](#lockreason8) | Yes | SIM card lock type. | 1051