• 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> **NOTE**
377>
378> Before using this API, you must declare the **ohos.permission.READ_CALL_LOG** permission (a system permission).
379
380**System capability**: SystemCapability.Telephony.StateRegistry
381
382**Parameters**
383
384| Name  | Type                                          | Mandatory| Description                                                       |
385| -------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
386| type     | string                                        | Yes  | Call status change event. This field has a fixed value of **callStateChange**.               |
387| callback | Callback\<[CallStateInfo](#callstateinfo11)\> | Yes  | Callback used to return the result. For details, see [CallState](js-apis-call.md#callstate).<br>**number**: phone number.|
388
389**Error codes**
390
391For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Telephony Error Codes](errorcode-telephony.md).
392
393| ID|                  Error Message                   |
394| -------- | -------------------------------------------- |
395| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
396| 8300001  | Invalid parameter value.                     |
397| 8300002  | Service connection failed.                   |
398| 8300003  | System internal error.                       |
399| 8300999  | Unknown error.                               |
400
401**Example**
402
403```ts
404observer.on('callStateChange', (data: observer.CallStateInfo) => {
405    console.log("on callStateChange, data:" + JSON.stringify(data));
406});
407```
408
409
410## observer.on('callStateChange')
411
412on(type: 'callStateChange', options: ObserverOptions, callback: Callback\<CallStateInfo\>): void
413
414Registers an observer for call status change events. This API uses an asynchronous callback to return the execution result.
415
416> **NOTE**
417>
418> Before using this API, you must declare the **ohos.permission.READ_CALL_LOG** permission (a system permission).
419
420**System capability**: SystemCapability.Telephony.StateRegistry
421
422**Parameters**
423
424| Name  | Type                                                        | Mandatory| Description                                                        |
425| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
426| type     | string                                                       | Yes  | Call status change event. This field has a fixed value of **callStateChange**.              |
427| options  | [ObserverOptions](#observeroptions11)                        | Yes  | Event subscription parameters.                                 |
428| callback | Callback\<[CallStateInfo](#callstateinfo11)\>                | Yes  | Callback used to return the result. For details, see [CallState](js-apis-call.md#callstate).<br>**number**: phone number.|
429
430**Error codes**
431
432For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Telephony Error Codes](errorcode-telephony.md).
433
434| ID|                  Error Message                   |
435| -------- | -------------------------------------------- |
436| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
437| 8300001  | Invalid parameter value.                     |
438| 8300002  | Service connection failed.                   |
439| 8300003  | System internal error.                       |
440| 8300999  | Unknown error.                               |
441
442**Example**
443
444```ts
445let options: observer.ObserverOptions = {
446    slotId: 0
447}
448observer.on('callStateChange', options, (data: observer.CallStateInfo) => {
449    console.log("on callStateChange, data:" + JSON.stringify(data));
450});
451```
452
453
454## observer.off('callStateChange')
455
456off(type: 'callStateChange', callback?: Callback\<CallStateInfo\>): void
457
458Unregisters the observer for call status change events. This API uses an asynchronous callback to return the execution result.
459
460> **NOTE**
461>
462> 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.
463
464**System capability**: SystemCapability.Telephony.StateRegistry
465
466**Parameters**
467
468| Name  | Type                                                        | Mandatory| Description                                                        |
469| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
470| type     | string                                                       | Yes  | Call status change event. This field has a fixed value of **callStateChange**.              |
471| callback | Callback\<[CallStateInfo](#callstateinfo11)\>                | No  | Callback used to return the result. For details, see [CallState](js-apis-call.md#callstate).<br>**number**: phone number.|
472
473**Error codes**
474
475For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Telephony Error Codes](errorcode-telephony.md).
476
477| ID|                  Error Message                   |
478| -------- | -------------------------------------------- |
479| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
480| 8300001  | Invalid parameter value.                     |
481| 8300002  | Service connection failed.                   |
482| 8300003  | System internal error.                       |
483| 8300999  | Unknown error.                               |
484
485**Example**
486
487```ts
488let callback: (data: observer.CallStateInfo) => void = (data: observer.CallStateInfo) => {
489    console.log("on callStateChange, data:" + JSON.stringify(data));
490}
491observer.on('callStateChange', callback);
492// 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.
493observer.off('callStateChange', callback);
494observer.off('callStateChange');
495```
496
497
498## observer.on('cellularDataConnectionStateChange')<sup>7+</sup>
499
500on\(type: 'cellularDataConnectionStateChange', callback: Callback\<DataConnectionStateInfo\>\): void
501
502Registers an observer for connection status change events of the cellular data link. This API uses an asynchronous callback to return the result.
503
504**System capability**: SystemCapability.Telephony.StateRegistry
505
506**Parameters**
507
508| Name  | Type                              | Mandatory| Description                                                                |
509| -------- | --------------------------------- | ---- | -------------------------------------------------------------------- |
510| type     | string                            | Yes  | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.|
511| 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).|
512
513**Error codes**
514
515For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Telephony Error Codes](errorcode-telephony.md).
516
517| ID|                  Error Message                   |
518| -------- | -------------------------------------------- |
519| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
520| 8300001  | Invalid parameter value.                     |
521| 8300002  | Service connection failed.                   |
522| 8300003  | System internal error.                       |
523| 8300999  | Unknown error.                               |
524
525**Example**
526
527```ts
528observer.on('cellularDataConnectionStateChange', (data: observer.DataConnectionStateInfo) => {
529    console.log("on cellularDataConnectionStateChange, data:" + JSON.stringify(data));
530});
531```
532
533
534## observer.on('cellularDataConnectionStateChange')<sup>7+</sup>
535
536on\(type: 'cellularDataConnectionStateChange', options: ObserverOptions, callback: Callback\<DataConnectionStateInfo\>\): void
537
538Registers 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.
539
540**System capability**: SystemCapability.Telephony.StateRegistry
541
542**Parameters**
543
544| Name  | Type                                                        | Mandatory| Description                                                        |
545| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
546| type     | string                                                       | Yes  | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.|
547| options  | [ObserverOptions](#observeroptions11)                        | Yes  | Event subscription parameters.            |
548| 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).|
549
550**Error codes**
551
552For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Telephony Error Codes](errorcode-telephony.md).
553
554| ID|                  Error Message                   |
555| -------- | -------------------------------------------- |
556| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
557| 8300001  | Invalid parameter value.                     |
558| 8300002  | Service connection failed.                   |
559| 8300003  | System internal error.                       |
560| 8300999  | Unknown error.                               |
561
562**Example**
563
564```ts
565let options: observer.ObserverOptions = {
566    slotId: 0
567}
568observer.on('cellularDataConnectionStateChange', options, (data: observer.DataConnectionStateInfo) => {
569    console.log("on cellularDataConnectionStateChange, data:" + JSON.stringify(data));
570});
571```
572
573
574## observer.off('cellularDataConnectionStateChange')<sup>7+</sup>
575
576off\(type: 'cellularDataConnectionStateChange',  callback?: Callback\<DataConnectionStateInfo\>\): void
577
578Unregisters the observer for connection status change events of the cellular data link. This API uses an asynchronous callback to return the result.
579
580> **NOTE**
581>
582> 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.
583
584**System capability**: SystemCapability.Telephony.StateRegistry
585
586**Parameters**
587
588| Name  | Type                                                        | Mandatory| Description                                                        |
589| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
590| type     | string                                                       | Yes  | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.|
591| 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).|
592
593**Error codes**
594
595For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Telephony Error Codes](errorcode-telephony.md).
596
597| ID|                  Error Message                   |
598| -------- | -------------------------------------------- |
599| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
600| 8300001  | Invalid parameter value.                     |
601| 8300002  | Service connection failed.                   |
602| 8300003  | System internal error.                       |
603| 8300999  | Unknown error.                               |
604
605**Example**
606
607```ts
608let callback: (data: observer.DataConnectionStateInfo) => void = (data: observer.DataConnectionStateInfo) => {
609    console.log("on cellularDataConnectionStateChange, data:" + JSON.stringify(data));
610}
611observer.on('cellularDataConnectionStateChange', callback);
612// 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.
613observer.off('cellularDataConnectionStateChange', callback);
614observer.off('cellularDataConnectionStateChange');
615```
616
617
618## observer.on('cellularDataFlowChange')<sup>7+</sup>
619
620on\(type: 'cellularDataFlowChange', callback: Callback\<DataFlowType\>\): void
621
622Registers 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.
623
624**System capability**: SystemCapability.Telephony.StateRegistry
625
626**Parameters**
627
628| Name  | Type                                                        | Mandatory| Description                                                        |
629| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
630| type     | string                                                       | Yes | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**.        |
631| 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).|
632
633**Error codes**
634
635For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Telephony Error Codes](errorcode-telephony.md).
636
637| ID|                  Error Message                   |
638| -------- | -------------------------------------------- |
639| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
640| 8300001  | Invalid parameter value.                     |
641| 8300002  | Service connection failed.                   |
642| 8300003  | System internal error.                       |
643| 8300999  | Unknown error.                               |
644
645**Example**
646
647```ts
648import { data } from '@kit.TelephonyKit';
649
650observer.on('cellularDataFlowChange', (data: data.DataFlowType) => {
651    console.log("on cellularDataFlowChange, data:" + JSON.stringify(data));
652});
653```
654
655
656## observer.on('cellularDataFlowChange')<sup>7+</sup>
657
658on\(type: 'cellularDataFlowChange', options: ObserverOptions,  callback: Callback\<DataFlowType\>\): void
659
660Registers 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.
661
662**System capability**: SystemCapability.Telephony.StateRegistry
663
664**Parameters**
665
666| Name  | Type                                                      | Mandatory| Description                                                        |
667| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
668| type     | string                                                     | Yes  | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**.        |
669| options   | [ObserverOptions](#observeroptions11)                     | Yes  | Event subscription parameters.                                                  |
670| 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).|
671
672**Error codes**
673
674For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Telephony Error Codes](errorcode-telephony.md).
675
676| ID|                  Error Message                   |
677| -------- | -------------------------------------------- |
678| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
679| 8300001  | Invalid parameter value.                     |
680| 8300002  | Service connection failed.                   |
681| 8300003  | System internal error.                       |
682| 8300999  | Unknown error.                               |
683
684**Example**
685
686```ts
687import { data } from '@kit.TelephonyKit';
688
689let options: observer.ObserverOptions = {
690    slotId: 0
691}
692observer.on('cellularDataFlowChange', options, (data: data.DataFlowType) => {
693    console.log("on cellularDataFlowChange, data:" + JSON.stringify(data));
694});
695```
696
697
698## observer.off('cellularDataFlowChange')<sup>7+</sup>
699
700off\(type: 'cellularDataFlowChange', callback?: Callback\<DataFlowType\>\): void
701
702Unregisters 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.
703
704> **NOTE**
705>
706> 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.
707
708**System capability**: SystemCapability.Telephony.StateRegistry
709
710**Parameters**
711
712| Name  | Type                                                               | Mandatory| Description                                                        |
713| -------- | ------------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
714| type     | string                                                             | Yes  | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**.  |
715| 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).|
716
717**Error codes**
718
719For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Telephony Error Codes](errorcode-telephony.md).
720
721| ID|                  Error Message                   |
722| -------- | -------------------------------------------- |
723| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
724| 8300001  | Invalid parameter value.                     |
725| 8300002  | Service connection failed.                   |
726| 8300003  | System internal error.                       |
727| 8300999  | Unknown error.                               |
728
729**Example**
730
731```ts
732import { data } from '@kit.TelephonyKit';
733
734let callback: (data: data.DataFlowType) => void = (data: data.DataFlowType) => {
735    console.log("on cellularDataFlowChange, data:" + JSON.stringify(data));
736}
737observer.on('cellularDataFlowChange', callback);
738// 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.
739observer.off('cellularDataFlowChange', callback);
740observer.off('cellularDataFlowChange');
741```
742
743
744## observer.on('simStateChange')<sup>7+</sup>
745
746on\(type: 'simStateChange', callback: Callback\<SimStateData\>\): void
747
748Registers an observer for SIM card status change events. This API uses an asynchronous callback to return the result.
749
750**System capability**: SystemCapability.Telephony.StateRegistry
751
752**Parameters**
753
754| Name  | Type                                                        | Mandatory| Description                                                        |
755| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
756| type     | string                                                       | Yes  | SIM status change event. This field has a fixed value of **simStateChange**.                |
757| callback | Callback\<[SimStateData](#simstatedata7)\> | Yes  | Callback used to return the result.|
758
759**Error codes**
760
761For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Telephony Error Codes](errorcode-telephony.md).
762
763| ID|                 Error Message                    |
764| -------- | -------------------------------------------- |
765| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
766| 8300001  | Invalid parameter value.                     |
767| 8300002  | Service connection failed.                   |
768| 8300003  | System internal error.                       |
769| 8300999  | Unknown error.                               |
770
771**Example**
772
773```ts
774observer.on('simStateChange', (data: observer.SimStateData) => {
775    console.log("on simStateChange, data:" + JSON.stringify(data));
776});
777```
778
779
780## observer.on('simStateChange')<sup>7+</sup>
781
782on\(type: 'simStateChange', options: ObserverOptions, callback: Callback\<SimStateData\>\): void
783
784Registers an observer for status change events of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.
785
786**System capability**: SystemCapability.Telephony.StateRegistry
787
788**Parameters**
789
790| Name  | Type                                                        | Mandatory| Description                                                        |
791| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
792| type     | string                                                       | Yes  | SIM status change event. This field has a fixed value of **simStateChange**.                |
793| options   | [ObserverOptions](#observeroptions11)                       | Yes  | Event subscription parameters.                                 |
794| callback | Callback\<[SimStateData](#simstatedata7)\> | Yes  | Callback used to return the result.|
795
796**Error codes**
797
798For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Telephony Error Codes](errorcode-telephony.md).
799
800| ID|                 Error Message                    |
801| -------- | -------------------------------------------- |
802| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
803| 8300001  | Invalid parameter value.                     |
804| 8300002  | Service connection failed.                   |
805| 8300003  | System internal error.                       |
806| 8300999  | Unknown error.                               |
807
808**Example**
809
810```ts
811let options: observer.ObserverOptions = {
812    slotId: 0
813}
814observer.on('simStateChange', options, (data: observer.SimStateData) => {
815    console.log("on simStateChange, data:" + JSON.stringify(data));
816});
817```
818
819
820## observer.off('simStateChange')<sup>7+</sup>
821
822off\(type: 'simStateChange', callback?: Callback\<SimStateData\>\): void
823
824Unregisters the observer for SIM card status change events. This API uses an asynchronous callback to return the result.
825
826> **NOTE**
827>
828> 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.
829
830**System capability**: SystemCapability.Telephony.StateRegistry
831
832**Parameters**
833
834| Name  | Type                                                        | Mandatory| Description                                                        |
835| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
836| type     | string                                                       | Yes  | SIM status change event. This field has a fixed value of **simStateChange**.                |
837| callback | Callback\<[SimStateData](#simstatedata7)\> | No  | Callback used to return the result.|
838
839**Error codes**
840
841For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Telephony Error Codes](errorcode-telephony.md).
842
843| ID|                 Error Message                    |
844| -------- | -------------------------------------------- |
845| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
846| 8300001  | Invalid parameter value.                     |
847| 8300002  | Service connection failed.                   |
848| 8300003  | System internal error.                       |
849| 8300999  | Unknown error.                               |
850
851**Example**
852
853```ts
854let callback: (data: observer.SimStateData) => void = (data: observer.SimStateData) => {
855    console.log("on simStateChange, data:" + JSON.stringify(data));
856}
857observer.on('simStateChange', callback);
858// 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.
859observer.off('simStateChange', callback);
860observer.off('simStateChange');
861```
862
863## observer.on('iccAccountInfoChange')<sup>10+</sup>
864
865on\(type: 'iccAccountInfoChange', callback: Callback\<void\>\): void
866
867Registers an observer for account information change events of the SIM card. This API uses an asynchronous callback to return the result.
868
869**System capability**: SystemCapability.Telephony.StateRegistry
870
871**Parameters**
872
873| Name  | Type                                                        | Mandatory| Description                                                        |
874| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
875| type     | string                                                       | Yes  | Account information change event. This field has a fixed value of **iccAccountInfoChange**.                |
876| callback | Callback\<void\> | Yes  | Callback used to return the result.|
877
878**Error codes**
879
880For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Telephony Error Codes](errorcode-telephony.md).
881
882| ID|                 Error Message                    |
883| -------- | -------------------------------------------- |
884| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
885| 8300001  | Invalid parameter value.                     |
886| 8300002  | Service connection failed.                   |
887| 8300003  | System internal error.                       |
888| 8300999  | Unknown error.                               |
889
890**Example**
891
892```ts
893observer.on('iccAccountInfoChange', () => {
894    console.log("on iccAccountInfoChange success");
895});
896```
897
898
899## observer.off('iccAccountInfoChange')<sup>10+</sup>
900
901off\(type: 'iccAccountInfoChange', callback?: Callback\<void\>\): void
902
903Unregisters the observer for account information change events of the SIM card. This API uses an asynchronous callback to return the result.
904
905> **NOTE**
906>
907> 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.
908
909**System capability**: SystemCapability.Telephony.StateRegistry
910
911**Parameters**
912
913| Name  | Type                                                        | Mandatory| Description                                                        |
914| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
915| type     | string                                                       | Yes  | Account information change event. This field has a fixed value of **iccAccountInfoChange**.                |
916| callback | Callback\<void\> | No  | Callback used to return the result.|
917
918**Error codes**
919
920For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Telephony Error Codes](errorcode-telephony.md).
921
922| ID|                 Error Message                    |
923| -------- | -------------------------------------------- |
924| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
925| 8300001  | Invalid parameter value.                     |
926| 8300002  | Service connection failed.                   |
927| 8300003  | System internal error.                       |
928| 8300999  | Unknown error.                               |
929
930**Example**
931
932```ts
933let callback: () => void = () => {
934    console.log("on iccAccountInfoChange success");
935}
936observer.on('iccAccountInfoChange', callback);
937// 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.
938observer.off('iccAccountInfoChange', callback);
939observer.off('iccAccountInfoChange');
940```
941
942
943## LockReason<sup>8+</sup>
944
945Enumerates SIM card lock types.
946
947**System capability**: SystemCapability.Telephony.StateRegistry
948
949| Name       | Value  | Description             |
950| ----------- | ---- | ----------------- |
951| SIM_NONE    | 0    | No lock.           |
952| SIM_PIN     | 1    | PIN lock.          |
953| SIM_PUK     | 2    | PUK lock.          |
954| SIM_PN_PIN  | 3    | Network PIN lock.      |
955| SIM_PN_PUK  | 4    | Network PUK lock.      |
956| SIM_PU_PIN  | 5    | Subnet PIN lock.      |
957| SIM_PU_PUK  | 6    | Subnet PUK lock.      |
958| SIM_PP_PIN  | 7    | Service provider PIN lock.|
959| SIM_PP_PUK  | 8    | Service provider PUK lock.|
960| SIM_PC_PIN  | 9    | Organization PIN lock.      |
961| SIM_PC_PUK  | 10   | Organization PUK lock.      |
962| SIM_SIM_PIN | 11   | SIM PIN lock.      |
963| SIM_SIM_PUK | 12   | SIM PUK lock.      |
964
965
966## SimStateData<sup>7+</sup>
967
968Enumerates SIM card types and states.
969
970**System capability**: SystemCapability.Telephony.StateRegistry
971
972|     Name           |                 Type               | Mandatory| Description                                                     |
973| ------------------- | ----------------------------------- | ---- | --------------------------------------------------------  |
974| type                | [CardType](js-apis-sim.md#cardtype7) | Yes  | SIM card type.|
975| state               | [SimState](js-apis-sim.md#simstate) | Yes  | SIM card state.|
976| reason<sup>8+</sup> | [LockReason](#lockreason8)          | Yes  | SIM card lock type.                                            |
977
978
979## CallStateInfo<sup>11+</sup>
980
981Defines information about the call status.
982
983**System capability**: SystemCapability.Telephony.StateRegistry
984
985|     Name           |                 Type                   | Mandatory| Description    |
986| ------------------- | -------------------------------------- | ---- | -------- |
987| state               | [CallState](js-apis-call.md#callstate) | Yes  | Call type.|
988| number              | string                                 | Yes  | Phone number.|
989
990
991## DataConnectionStateInfo<sup>11+</sup>
992
993Defines information about the data connection status.
994
995**System capability**: SystemCapability.Telephony.StateRegistry
996
997|     Name           |                 Type                                           | Mandatory| Description        |
998| ------------------- | ---------------------------------------------------------------| ---- | ------------ |
999| state               | [DataConnectState](js-apis-telephony-data.md#dataconnectstate) | Yes  | Data connection status.|
1000| network             | [RatType](js-apis-radio.md#radiotechnology)                    | Yes  | Network type.    |
1001
1002
1003## ObserverOptions<sup>11+</sup>
1004
1005Defines event subscription parameters.
1006
1007**System capability**: SystemCapability.Telephony.StateRegistry
1008
1009|     Name           |         Type     | Mandatory | Description                                   |
1010| ------------------- | ------------------| ---- | --------------------------------------- |
1011| slotId              | number            | Yes  | Card slot ID.<br>- **0**: card slot 1.<br>- **1**: card slot 2.   |
1012