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