• 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```
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```js
49observer.on('networkStateChange', data => {
50    console.log("on networkStateChange, data:" + JSON.stringify(data));
51});
52```
53
54
55## observer.on('networkStateChange')
56
57on\(type: \'networkStateChange\', options: { slotId: number }, callback: Callback<NetworkState\>\): void;
58
59Registers an observer for network status change events of the SIM card in the specified slot. This API uses an asynchronous callback to return the execution result.
60
61**Required permission**: ohos.permission.GET_NETWORK_INFO
62
63**System capability**: SystemCapability.Telephony.StateRegistry
64
65**Parameters**
66
67|  Name |                              Type                        | Mandatory|                            Description                                  |
68| -------- | --------------------------------------------------------- | ---- | ---------------------------------------------------------------- |
69| type     | string                                                    | Yes  | Network status change event. This field has a fixed value of **networkStateChange**.                |
70| slotId   | number                                                    | Yes  | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2                            |
71| callback | Callback\<[NetworkState](js-apis-radio.md#networkstate)\> | Yes  | Callback used to return the result. For details, see [NetworkState](js-apis-radio.md#networkstate).|
72
73**Error codes**
74
75For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
76
77| ID|                  Error Message                   |
78| -------- | -------------------------------------------- |
79| 201      | Permission denied.                           |
80| 401      | Parameter error.                             |
81| 8300001  | Invalid parameter value.                     |
82| 8300002  | Operation failed. Cannot connect to service. |
83| 8300003  | System internal error.                       |
84| 8300999  | Unknown error code.                          |
85
86**Example**
87
88```js
89observer.on('networkStateChange', {slotId: 0}, data => {
90    console.log("on networkStateChange, data:" + JSON.stringify(data));
91});
92```
93
94
95## observer.off('networkStateChange')
96
97off\(type: \'networkStateChange\', callback?: Callback<NetworkState\>\): void;
98
99Unregisters the observer for network status change events. This API uses an asynchronous callback to return the execution result.
100
101>**NOTE**
102>
103>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.
104
105**System capability**: SystemCapability.Telephony.StateRegistry
106
107**Parameters**
108
109| Name  | Type                                                     | Mandatory| Description                                                        |
110| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
111| type     | string                                                    | Yes  | Network status change event. This field has a fixed value of **networkStateChange**.                |
112| callback | Callback\<[NetworkState](js-apis-radio.md#networkstate)\> | No  | Callback used to return the result. For details, see [NetworkState](js-apis-radio.md#networkstate).|
113
114| ID|                  Error Message                   |
115| -------- | -------------------------------------------- |
116| 401      | Parameter error.                             |
117| 8300001  | Invalid parameter value.                     |
118| 8300002  | Operation failed. Cannot connect to service. |
119| 8300003  | System internal error.                       |
120| 8300999  | Unknown error code.                          |
121
122**Example**
123
124```js
125let callback = data => {
126    console.log("on networkStateChange, data:" + JSON.stringify(data));
127}
128observer.on('networkStateChange', callback);
129// 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.
130observer.off('networkStateChange', callback);
131observer.off('networkStateChange');
132```
133
134## observer.on('signalInfoChange')
135
136on\(type: \'signalInfoChange\', callback: Callback<Array<SignalInformation\>\>): void;
137
138Registers an observer for signal status change events. This API uses an asynchronous callback to return the execution result.
139
140**System capability**: SystemCapability.Telephony.StateRegistry
141
142**Parameters**
143
144| Name  | Type                                                        | Mandatory| Description                                                        |
145| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
146| type     | string                                                       | Yes  | Signal status change event. This field has a fixed value of **signalInfoChange**.             |
147| 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).|
148
149**Error codes**
150
151For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
152
153| ID|                  Error Message                   |
154| -------- | -------------------------------------------- |
155| 201      | Permission denied.                           |
156| 401      | Parameter error.                             |
157| 8300001  | Invalid parameter value.                     |
158| 8300002  | Operation failed. Cannot connect to service. |
159| 8300003  | System internal error.                       |
160| 8300999  | Unknown error code.                          |
161
162**Example**
163
164```js
165observer.on('signalInfoChange', data => {
166    console.log("on signalInfoChange, data:" + JSON.stringify(data));
167});
168```
169
170
171## observer.on('signalInfoChange')
172
173on\(type: \'signalInfoChange\', options: { slotId: number }, callback: Callback<Array<SignalInformation\>\>): void;
174
175Registers 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.
176
177**System capability**: SystemCapability.Telephony.StateRegistry
178
179**Parameters**
180
181| Name  | Type                                                        | Mandatory| Description                                                        |
182| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
183| type     | string                                                       | Yes  | Signal status change event. This field has a fixed value of **signalInfoChange**.             |
184| slotId   | number                                                       | Yes  | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2                      |
185| 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).|
186
187**Error codes**
188
189For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
190
191| ID|                  Error Message                   |
192| -------- | -------------------------------------------- |
193| 201      | Permission denied.                           |
194| 401      | Parameter error.                             |
195| 8300001  | Invalid parameter value.                     |
196| 8300002  | Operation failed. Cannot connect to service. |
197| 8300003  | System internal error.                       |
198| 8300999  | Unknown error code.                          |
199
200**Example**
201
202```js
203observer.on('signalInfoChange', {slotId: 0}, data => {
204    console.log("on signalInfoChange, data:" + JSON.stringify(data));
205});
206```
207
208
209## observer.off('signalInfoChange')
210
211off\(type: \'signalInfoChange\', callback?: Callback<Array<SignalInformation\>\>): void;
212
213Unregisters the observer for signal status change events. This API uses an asynchronous callback to return the execution result.
214
215>**NOTE**
216>
217>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.
218
219**System capability**: SystemCapability.Telephony.StateRegistry
220
221**Parameters**
222
223| Name  | Type                                                        | Mandatory| Description                                                        |
224| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
225| type     | string                                                       | Yes  | Signal status change event. This field has a fixed value of **signalInfoChange**.             |
226| 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).|
227
228**Error codes**
229
230For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
231
232| ID|                  Error Message                   |
233| -------- | -------------------------------------------- |
234| 401      | Parameter error.                             |
235| 8300001  | Invalid parameter value.                     |
236| 8300002  | Operation failed. Cannot connect to service. |
237| 8300003  | System internal error.                       |
238| 8300999  | Unknown error code.                          |
239
240**Example**
241
242```js
243let callback = data => {
244    console.log("on signalInfoChange, data:" + JSON.stringify(data));
245}
246observer.on('signalInfoChange', callback);
247// 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.
248observer.off('signalInfoChange', callback);
249observer.off('signalInfoChange');
250```
251
252## observer.on('cellInfoChange')<sup>8+</sup>
253
254on\(type: \'cellInfoChange\', callback: Callback<CellInformation\>\): void;
255
256Registers an observer for cell information change events. This API uses an asynchronous callback to return the result.
257
258**System API**: This is a system API.
259
260**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
261
262**System capability**: SystemCapability.Telephony.StateRegistry
263
264**Parameters**
265
266| Name  | Type                                                     | Mandatory| Description                                                        |
267| -------- | --------------------------------------------------------- | ---- |------------------------------------------------------------|
268| type     | string                                                    | Yes  | Cell information change event. This field has a fixed value of **cellInfoChange**.             |
269| callback | Callback\<[CellInformation](js-apis-radio.md#cellinformation8)\> | Yes  | Callback used to return the result.|
270
271**Error codes**
272
273| ID|                  Error Message                   |
274| -------- | -------------------------------------------- |
275| 201      | Permission denied.                           |
276| 401      | Parameter error.                             |
277| 8300001  | Invalid parameter value.                     |
278| 8300002  | Operation failed. Cannot connect to service. |
279| 8300003  | System internal error.                       |
280| 8300999  | Unknown error code.                          |
281
282**Example**
283
284```js
285observer.on('cellInfoChange', data => {
286    console.log("on cellInfoChange, data:" + JSON.stringify(data));
287});
288```
289
290
291## observer.on('cellInfoChange')<sup>8+</sup>
292
293on\(type: \'cellInfoChange\', options: { slotId: number }, callback: Callback<CellInformation\>\): void;
294
295Registers 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.
296
297**System API**: This is a system API.
298
299**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
300
301**System capability**: SystemCapability.Telephony.StateRegistry
302
303**Parameters**
304
305| Name| Type                                              | Mandatory| Description                                                        |
306| ------ |--------------------------------------------------| ---- |------------------------------------------------------------|
307| type     | string                                           | Yes  | Cell information change event. This field has a fixed value of **cellInfoChange**.                                                  |
308| slotId | number                                           | Yes  | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2                             |
309| callback | Callback\<[CellInformation](js-apis-radio.md#cellinformation8)\> | Yes  | Callback used to return the result.|
310
311**Error codes**
312
313| ID|                  Error Message                   |
314| -------- | -------------------------------------------- |
315| 201      | Permission denied.                           |
316| 401      | Parameter error.                             |
317| 8300001  | Invalid parameter value.                     |
318| 8300002  | Operation failed. Cannot connect to service. |
319| 8300003  | System internal error.                       |
320| 8300999  | Unknown error code.                          |
321
322**Example**
323
324```js
325observer.on('cellInfoChange', {slotId: 0}, data => {
326    console.log("on cellInfoChange, data:" + JSON.stringify(data));
327});
328```
329
330
331## observer.off('cellInfoChange')<sup>8+</sup>
332
333off\(type: \'cellInfoChange\', callback?: Callback<CellInformation\>\): void;
334
335Unregisters the observer for cell information change events. This API uses an asynchronous callback to return the result.
336
337>**NOTE**
338>
339>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.
340
341**System API**: This is a system API.
342
343**System capability**: SystemCapability.Telephony.StateRegistry
344
345**Parameters**
346
347| Name  | Type                                                     | Mandatory| Description                                                        |
348| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
349| type     | string                                                    | Yes  | Cell information change event. This field has a fixed value of **cellInfoChange**.                                           |
350| callback | Callback\<[CellInformation](js-apis-radio.md#cellinformation8)\> | No  | Callback used to return the result.|
351
352| ID|                  Error Message                   |
353| -------- | -------------------------------------------- |
354| 401      | Parameter error.                             |
355| 8300001  | Invalid parameter value.                     |
356| 8300002  | Operation failed. Cannot connect to service. |
357| 8300003  | System internal error.                       |
358| 8300999  | Unknown error code.                          |
359
360**Example**
361
362```js
363let callback = data => {
364    console.log("on cellInfoChange, data:" + JSON.stringify(data));
365}
366observer.on('cellInfoChange', callback);
367// 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.
368observer.off('cellInfoChange', callback);
369observer.off('cellInfoChange');
370```
371
372## observer.on('callStateChange')
373
374on(type: 'callStateChange', callback: Callback\<{ state: CallState, number: string }\>): void;
375
376Registers an observer for call status change events. This API uses an asynchronous callback to return the execution result.
377
378**System capability**: SystemCapability.Telephony.StateRegistry
379
380**Parameters**
381
382| Name  | Type                                                        | Mandatory| Description                                                        |
383| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
384| type     | string                                                       | Yes  | Call status change event. This field has a fixed value of **callStateChange**.              |
385| callback | Callback\<{ state: [CallState](js-apis-call.md#callstate), number: string }\> | Yes  | Callback function. For details, see [CallState](js-apis-call.md#callstate) in call.<br>**number**: phone number.|
386
387**Error codes**
388
389For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
390
391| ID|                  Error Message                   |
392| -------- | -------------------------------------------- |
393| 401      | Parameter error.                             |
394| 8300001  | Invalid parameter value.                     |
395| 8300002  | Operation failed. Cannot connect to service. |
396| 8300003  | System internal error.                       |
397| 8300999  | Unknown error code.                          |
398
399**Example**
400
401```js
402observer.on('callStateChange', value => {
403    console.log("on callStateChange, state:" + value.state + ", number:" + value.number);
404});
405```
406
407
408## observer.on('callStateChange')
409
410on(type: 'callStateChange', options: { slotId: number }, callback: Callback<{ state:CallState, number: string }>): void;
411
412Registers an observer for call status change events. This API uses an asynchronous callback to return the execution result.
413
414**System capability**: SystemCapability.Telephony.StateRegistry
415
416**Parameters**
417
418| Name  | Type                                                        | Mandatory| Description                                                        |
419| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
420| type     | string                                                       | Yes  | Call status change event. This field has a fixed value of **callStateChange**.              |
421| slotId   | number                                                       | Yes  | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2                      |
422| callback | Callback\<{ state: [CallState](js-apis-call.md#callstate), number: string }\> | Yes  | Callback function. For details, see [CallState](js-apis-call.md#callstate) in call.<br>**number**: phone number.|
423
424**Error codes**
425
426For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
427
428| ID|                  Error Message                   |
429| -------- | -------------------------------------------- |
430| 401      | Parameter error.                             |
431| 8300001  | Invalid parameter value.                     |
432| 8300002  | Operation failed. Cannot connect to service. |
433| 8300003  | System internal error.                       |
434| 8300999  | Unknown error code.                          |
435
436**Example**
437
438```js
439observer.on('callStateChange', {slotId: 0}, value => {
440    console.log("on callStateChange, state:" + value.state + ", number:" + value.number);
441});
442```
443
444
445## observer.off('callStateChange')
446
447off(type: 'callStateChange', callback?: Callback<{ state: CallState, number: string }>): void;
448
449Unregisters the observer for call status change events. This API uses an asynchronous callback to return the execution result.
450
451>**NOTE**
452>
453>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.
454
455**System capability**: SystemCapability.Telephony.StateRegistry
456
457**Parameters**
458
459| Name  | Type                                                        | Mandatory| Description                                                        |
460| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
461| type     | string                                                       | Yes  | Call status change event. This field has a fixed value of **callStateChange**.              |
462| callback | Callback\<{ state: [CallState](js-apis-call.md#callstate), number: string }\> | No  | Callback function. For details, see [CallState](js-apis-call.md#callstate) in call.<br>**number**: phone number.|
463
464**Error codes**
465
466For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
467
468| ID|                  Error Message                   |
469| -------- | -------------------------------------------- |
470| 401      | Parameter error.                             |
471| 8300001  | Invalid parameter value.                     |
472| 8300002  | Operation failed. Cannot connect to service. |
473| 8300003  | System internal error.                       |
474| 8300999  | Unknown error code.                          |
475
476**Example**
477
478```js
479let callback = value => {
480    console.log("on callStateChange, state:" + value.state + ", number:" + value.number);
481}
482observer.on('callStateChange', callback);
483// 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.
484observer.off('callStateChange', callback);
485observer.off('callStateChange');
486```
487
488
489## observer.on('cellularDataConnectionStateChange')<sup>7+</sup>
490
491on\(type: 'cellularDataConnectionStateChange', callback: Callback\<{ state: DataConnectState, network: RatType}\>\): void;
492
493Registers an observer for connection status change events of the cellular data link. This API uses an asynchronous callback to return the result.
494
495**System capability**: SystemCapability.Telephony.StateRegistry
496
497**Parameters**
498
499| Name  | Type                                                        | Mandatory| Description                                                        |
500| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
501| type     | string                                                       | Yes  | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.|
502| callback | Callback\<{ state: [DataConnectState](js-apis-telephony-data.md#dataconnectstate), network: [RatType](js-apis-radio.md#radiotechnology) }\> | Yes  | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).|
503
504**Error codes**
505
506For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
507
508| ID|                  Error Message                   |
509| -------- | -------------------------------------------- |
510| 401      | Parameter error.                             |
511| 8300001  | Invalid parameter value.                     |
512| 8300002  | Operation failed. Cannot connect to service. |
513| 8300003  | System internal error.                       |
514| 8300999  | Unknown error code.                          |
515
516**Example**
517
518```js
519observer.on('cellularDataConnectionStateChange', value => {
520    console.log("on cellularDataConnectionStateChange, state:" + value.state + ", network:" + value.network);
521});
522```
523
524
525## observer.on('cellularDataConnectionStateChange')<sup>7+</sup>
526
527on\(type: 'cellularDataConnectionStateChange', options: { slotId: number }, callback: Callback\<{ state: DataConnectState, network: RatType }\>\): void;
528
529Registers 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.
530
531**System capability**: SystemCapability.Telephony.StateRegistry
532
533**Parameters**
534
535| Name  | Type                                                        | Mandatory| Description                                                        |
536| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
537| type     | string                                                       | Yes  | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.|
538| slotId   | number                                                       | Yes  | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2                      |
539| callback | Callback\<{ state: [DataConnectState](js-apis-telephony-data.md#dataconnectstate), network: [RatType](js-apis-radio.md#radiotechnology) }\> | Yes  | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).|
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```js
556observer.on('cellularDataConnectionStateChange', {slotId: 0}, value => {
557    console.log("on cellularDataConnectionStateChange, state:" + value.state + ", network:" + value.network);
558});
559```
560
561
562## observer.off('cellularDataConnectionStateChange')<sup>7+</sup>
563
564off\(type: 'cellularDataConnectionStateChange',  callback?: Callback\<{ state: DataConnectState, network: RatType}\>\): void;
565
566Unregisters the observer for connection status change events of the cellular data link. This API uses an asynchronous callback to return the result.
567
568>**NOTE**
569>
570>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.
571
572**System capability**: SystemCapability.Telephony.StateRegistry
573
574**Parameters**
575
576| Name  | Type                                                        | Mandatory| Description                                                        |
577| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
578| type     | string                                                       | Yes  | Cellular data connection status event. This field has a fixed value of **cellularDataConnectionStateChange**.|
579| callback | Callback\<{ state: [DataConnectState](js-apis-telephony-data.md#dataconnectstate), network: [RatType](js-apis-radio.md#radiotechnology) }\> | No  | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).|
580
581**Error codes**
582
583For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
584
585| ID|                  Error Message                   |
586| -------- | -------------------------------------------- |
587| 401      | Parameter error.                             |
588| 8300001  | Invalid parameter value.                     |
589| 8300002  | Operation failed. Cannot connect to service. |
590| 8300003  | System internal error.                       |
591| 8300999  | Unknown error code.                          |
592
593**Example**
594
595```js
596let callback = value => {
597    console.log("on cellularDataConnectionStateChange, state:" + value.state + ", network:" + value.network);
598}
599observer.on('cellularDataConnectionStateChange', callback);
600// 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.
601observer.off('cellularDataConnectionStateChange', callback);
602observer.off('cellularDataConnectionStateChange');
603```
604
605
606## observer.on('cellularDataFlowChange')<sup>7+</sup>
607
608on\(type: 'cellularDataFlowChange', callback: Callback\<DataFlowType\>\): void;
609
610Registers 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.
611
612**System capability**: SystemCapability.Telephony.StateRegistry
613
614**Parameters**
615
616| Name  | Type                                                        | Mandatory| Description                                                        |
617| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
618| type     | string                                                       | Yes | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**.        |
619| 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).|
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```js
636observer.on('cellularDataFlowChange', data => {
637    console.log("on networkStateChange, data:" + JSON.stringify(data));
638});
639```
640
641
642## observer.on('cellularDataFlowChange')<sup>7+</sup>
643
644on\(type: 'cellularDataFlowChange', options: { slotId: number },  callback: Callback\<DataFlowType\>\): void;
645
646Registers 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.
647
648**System capability**: SystemCapability.Telephony.StateRegistry
649
650**Parameters**
651
652| Name  | Type                                                        | Mandatory| Description                                                        |
653| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
654| type     | string                                                       | Yes  | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**.        |
655| slotId   | number                                                       | Yes  | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2                                            |
656| 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).|
657
658**Error codes**
659
660For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
661
662| ID|                  Error Message                   |
663| -------- | -------------------------------------------- |
664| 401      | Parameter error.                             |
665| 8300001  | Invalid parameter value.                     |
666| 8300002  | Operation failed. Cannot connect to service. |
667| 8300003  | System internal error.                       |
668| 8300999  | Unknown error code.                          |
669
670**Example**
671
672```js
673observer.on('cellularDataFlowChange', {slotId: 0}, data => {
674    console.log("on cellularDataFlowChange, data:" + JSON.stringify(data));
675});
676```
677
678
679## observer.off('cellularDataFlowChange')<sup>7+</sup>
680
681off\(type: 'cellularDataFlowChange', callback?: Callback\<DataFlowType\>\): void;
682
683Unregisters 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.
684
685>**NOTE**
686>
687>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.
688
689**System capability**: SystemCapability.Telephony.StateRegistry
690
691**Parameters**
692
693| Name  | Type                                                               | Mandatory| Description                                                        |
694| -------- | ------------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
695| type     | string                                                             | Yes  | Cellular data flow change event. This field has a fixed value of **cellularDataFlowChange**.  |
696| 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).|
697
698**Error codes**
699
700For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
701
702| ID|                  Error Message                   |
703| -------- | -------------------------------------------- |
704| 401      | Parameter error.                             |
705| 8300001  | Invalid parameter value.                     |
706| 8300002  | Operation failed. Cannot connect to service. |
707| 8300003  | System internal error.                       |
708| 8300999  | Unknown error code.                          |
709
710**Example**
711
712```js
713let callback = data => {
714    console.log("on cellularDataFlowChange, data:" + JSON.stringify(data));
715}
716observer.on('cellularDataFlowChange', callback);
717// 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.
718observer.off('cellularDataFlowChange', callback);
719observer.off('cellularDataFlowChange');
720```
721
722
723## observer.on('simStateChange')<sup>7+</sup>
724
725on\(type: 'simStateChange', callback: Callback\<SimStateData\>\): void;
726
727Registers an observer for SIM card status change events. This API uses an asynchronous callback to return the result.
728
729**System capability**: SystemCapability.Telephony.StateRegistry
730
731**Parameters**
732
733| Name  | Type                                                        | Mandatory| Description                                                        |
734| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
735| type     | string                                                       | Yes  | SIM status change event. This field has a fixed value of **simStateChange**.                |
736| callback | Callback\<[SimStateData](#simstatedata7)\> | Yes  | Callback used to return the result.|
737
738**Error codes**
739
740For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
741
742| ID|                 Error Message                    |
743| -------- | -------------------------------------------- |
744| 401      | Parameter error.                             |
745| 8300001  | Invalid parameter value.                     |
746| 8300002  | Operation failed. Cannot connect to service. |
747| 8300003  | System internal error.                       |
748| 8300999  | Unknown error code.                          |
749
750**Example**
751
752```js
753observer.on('simStateChange', data => {
754    console.log("on simStateChange, data:" + JSON.stringify(data));
755});
756```
757
758
759## observer.on('simStateChange')<sup>7+</sup>
760
761on\(type: 'simStateChange', options: { slotId: number }, callback: Callback\<SimStateData\>\): void;
762
763Registers an observer for status change events of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.
764
765**System capability**: SystemCapability.Telephony.StateRegistry
766
767**Parameters**
768
769| Name  | Type                                                        | Mandatory| Description                                                        |
770| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
771| type     | string                                                       | Yes  | SIM status change event. This field has a fixed value of **simStateChange**.                |
772| slotId   | number                                                       | Yes  | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2                      |
773| callback | Callback\<[SimStateData](#simstatedata7)\> | Yes  | Callback used to return the result.|
774
775**Error codes**
776
777For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
778
779| ID|                 Error Message                    |
780| -------- | -------------------------------------------- |
781| 401      | Parameter error.                             |
782| 8300001  | Invalid parameter value.                     |
783| 8300002  | Operation failed. Cannot connect to service. |
784| 8300003  | System internal error.                       |
785| 8300999  | Unknown error code.                          |
786
787**Example**
788
789```js
790observer.on('simStateChange', {slotId: 0}, data => {
791    console.log("on simStateChange, data:" + JSON.stringify(data));
792});
793```
794
795
796## observer.off('simStateChange')<sup>7+</sup>
797
798off\(type: 'simStateChange', callback?: Callback\<SimStateData\>\): void;
799
800Unregisters the observer for SIM card status change events. This API uses an asynchronous callback to return the result.
801
802>**NOTE**
803>
804>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.
805
806**System capability**: SystemCapability.Telephony.StateRegistry
807
808**Parameters**
809
810| Name  | Type                                                        | Mandatory| Description                                                        |
811| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
812| type     | string                                                       | Yes  | SIM status change event. This field has a fixed value of **simStateChange**.                |
813| callback | Callback\<[SimStateData](#simstatedata7)\> | No  | Callback used to return the result.|
814
815**Error codes**
816
817For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
818
819| ID|                 Error Message                    |
820| -------- | -------------------------------------------- |
821| 401      | Parameter error.                             |
822| 8300001  | Invalid parameter value.                     |
823| 8300002  | Operation failed. Cannot connect to service. |
824| 8300003  | System internal error.                       |
825| 8300999  | Unknown error code.                          |
826
827**Example**
828
829```js
830let callback = data => {
831    console.log("on simStateChange, data:" + JSON.stringify(data));
832}
833observer.on('simStateChange', callback);
834// 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.
835observer.off('simStateChange', callback);
836observer.off('simStateChange');
837```
838
839
840## LockReason<sup>8+</sup>
841
842Enumerates SIM card lock types.
843
844**System capability**: SystemCapability.Telephony.StateRegistry
845
846| Name       | Value  | Description             |
847| ----------- | ---- | ----------------- |
848| SIM_NONE    | 0    | No lock.           |
849| SIM_PIN     | 1    | PIN lock.          |
850| SIM_PUK     | 2    | PUK lock.          |
851| SIM_PN_PIN  | 3    | Network PIN lock.      |
852| SIM_PN_PUK  | 4    | Network PUK lock.      |
853| SIM_PU_PIN  | 5    | Subnet PIN lock.      |
854| SIM_PU_PUK  | 6    | Subnet PUK lock.      |
855| SIM_PP_PIN  | 7    | Service provider PIN lock.|
856| SIM_PP_PUK  | 8    | Service provider PUK lock.|
857| SIM_PC_PIN  | 9    | Organization PIN lock.      |
858| SIM_PC_PUK  | 10   | Organization PUK lock.      |
859| SIM_SIM_PIN | 11   | SIM PIN lock.      |
860| SIM_SIM_PUK | 12   | SIM PUK lock.      |
861
862
863## SimStateData<sup>7+</sup>
864
865Enumerates SIM card types and states.
866
867**System capability**: SystemCapability.Telephony.StateRegistry
868
869|     Name           |                 Type               | Mandatory| Description                                                     |
870| ------------------- | ----------------------------------- | ---- | --------------------------------------------------------  |
871| type                | [CardType](js-apis-sim.md#cardtype7) | Yes  | SIM card type.|
872| state               | [SimState](js-apis-sim.md#simstate) | Yes  | SIM card state.|
873| reason<sup>8+</sup> | [LockReason](#lockreason8)          | Yes  | SIM card lock type.                                            |
874