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