We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
ReferencesSystemNetworkTelephony KitArkTS API@ohos.telephony.observer (Telephony Status Observer)

@ohos.telephony.observer (Telephony Status Observer)

Phone23+PC/2in126.0.0+Tablet23+TV26.0.0+Wearable23+Lite Wearable26.0.0+

The 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.

NOTE

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.

Modules to Import

Collapse
Word wrap
Dark theme
Copy code
  1. import { observer } from '@kit.TelephonyKit';

NetworkState

Phone23+Tablet23+Wearable23+

type NetworkState = radio.NetworkState

Defines the network status.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Type Description
radio.NetworkState Network status.

SignalInformation

Phone23+Tablet23+Wearable23+

type SignalInformation = radio.SignalInformation

Defines the signal strength.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Type Description
radio.SignalInformation Signal strength.

DataConnectState

Phone23+Tablet23+Wearable23+

type DataConnectState = data.DataConnectState

Describes the connection status of a cellular data link.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Type Description
data.DataConnectState Connection status of a cellular data link.

RatType

Phone23+Tablet23+Wearable23+

type RatType = radio.RadioTechnology

Enumerates the radio access technologies.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Type Description
radio.RadioTechnology Radio access technology.

DataFlowType

Phone23+Tablet23+Wearable23+

type DataFlowType = data.DataFlowType

Defines the cellular data flow type.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Type Description
data.DataFlowType Cellular data flow type.

CallState

Phone23+Tablet23+Wearable23+

type CallState = call.CallState

Enumerates call states.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Type Description
call.CallState Call state. (Only the CALL_STATE_OFFHOOK state is reported during an outgoing call.)

CCallState23+

Phone23+Tablet23+Wearable23+

type CCallState = call.CCallState

Enumerates carrier call states.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Type Description
call.CCallState Call state (of the carrier).

CardType

Phone23+Tablet23+Wearable23+

type CardType = sim.CardType

Enumerates SIM card types.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Type Description
sim.CardType SIM card type.

SimState

Phone23+Tablet23+Wearable23+

type SimState = sim.SimState

SIM card state.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Type Description
sim.SimState SIM card state.

TelCallState21+

Phone23+Tablet23+Wearable23+

type TelCallState = call.TelCallState

Enumerates call states.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Type Description
call.TelCallState Call state. (TEL_CALL_STATE_OFFHOOK and TEL_CALL_STATE_CONNECTED are used to report the dialed number status and the call connection status respectively during an outgoing call.)

observer.on('networkStateChange')

Phone23+Tablet23+Wearable23+

on(type: 'networkStateChange', callback: Callback<NetworkState>): void

Registers an observer for network status change events. This API uses an asynchronous callback to return the execution result.

Required permission: ohos.permission.GET_NETWORK_INFO

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Network status change event. This field has a fixed value of networkStateChange.
callback Callback<NetworkState> Yes Callback used to return the network status object. For details, see NetworkState.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. observer.on('networkStateChange', (data: observer.NetworkState) => {
  2. console.info("on networkStateChange, data:" + JSON.stringify(data));
  3. });

observer.on('networkStateChange')

Phone23+Tablet23+Wearable23+

on(type: 'networkStateChange', options: ObserverOptions, callback: Callback<NetworkState>): void

Registers 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.

Required permission: ohos.permission.GET_NETWORK_INFO

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Network status change event. This field has a fixed value of networkStateChange.
options ObserverOptions Yes Event subscription parameters.
callback Callback<NetworkState> Yes Callback used to return the network status object. For details, see NetworkState.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
201 Permission denied.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let options: observer.ObserverOptions = {
  2. slotId: 0
  3. }
  4. observer.on('networkStateChange', options, (data: observer.NetworkState) => {
  5. console.info("on networkStateChange, data:" + JSON.stringify(data));
  6. });

observer.off('networkStateChange')

Phone23+Tablet23+Wearable23+

off(type: 'networkStateChange', callback?: Callback<NetworkState>): void

Unregisters the observer for network status change events. This API uses an asynchronous callback to return the execution result.

NOTE

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.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Network status change event. This field has a fixed value of networkStateChange.
callback Callback<NetworkState> No Callback used to return the network status object. which is the NetworkState object.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let callback: (data: observer.NetworkState) => void = (data: observer.NetworkState) => {
  2. console.info("on networkStateChange, data:" + JSON.stringify(data));
  3. }
  4. observer.on('networkStateChange', callback);
  5. // 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.
  6. observer.off('networkStateChange', callback);
  7. observer.off('networkStateChange');

observer.on('signalInfoChange')

Phone23+Tablet23+Wearable23+

on(type: 'signalInfoChange', callback: Callback<Array<SignalInformation>>): void

Registers an observer for signal status change events. This API uses an asynchronous callback to return the execution result.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Signal status change event. This field has a fixed value of signalInfoChange.
callback Callback<Array<SignalInformation>> Yes Callback used to return the signal strength object. For details, see SignalInformation.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { radio } from '@kit.TelephonyKit';
  2. observer.on('signalInfoChange', (data: Array<radio.SignalInformation>) => {
  3. console.info("on signalInfoChange, data:" + JSON.stringify(data));
  4. });

observer.on('signalInfoChange')

Phone23+Tablet23+Wearable23+

on(type: 'signalInfoChange', options: ObserverOptions, callback: Callback<Array<SignalInformation>>): void

Registers 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.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Signal status change event. This field has a fixed value of signalInfoChange.
options ObserverOptions Yes Event subscription parameters.
callback Callback<Array<SignalInformation>> Yes Callback used to return the signal strength object. For details, see SignalInformation.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { radio } from '@kit.TelephonyKit';
  2. let options: observer.ObserverOptions = {
  3. slotId: 0
  4. }
  5. observer.on('signalInfoChange', options, (data: Array<radio.SignalInformation>) => {
  6. console.info("on signalInfoChange, data:" + JSON.stringify(data));
  7. });

observer.off('signalInfoChange')

Phone23+Tablet23+Wearable23+

off(type: 'signalInfoChange', callback?: Callback<Array<SignalInformation>>): void

Unregisters the observer for signal status change events. This API uses an asynchronous callback to return the execution result.

NOTE

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.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Signal status change event. This field has a fixed value of signalInfoChange.
callback Callback<Array<SignalInformation>> No Callback used to return the signal strength object. For details, see SignalInformation.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { radio } from '@kit.TelephonyKit';
  2. let callback: (data: Array<radio.SignalInformation>) => void = (data: Array<radio.SignalInformation>) => {
  3. console.info("on signalInfoChange, data:" + JSON.stringify(data));
  4. }
  5. observer.on('signalInfoChange', callback);
  6. // 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.
  7. observer.off('signalInfoChange', callback);
  8. observer.off('signalInfoChange');

observer.on('callStateChange')

Phone23+Tablet23+Wearable23+

on(type: 'callStateChange', callback: Callback<CallStateInfo>): void

Registers an observer for call status change events. This API uses an asynchronous callback to return the execution result.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Call status change event. This field has a fixed value of callStateChange.
callback Callback<CallStateInfo> Yes

Callback function used to return the result,

which is the CallStateInfo object. In this object:

- Only state is accessible to third-party applications. - number is only accessible to system applications.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. observer.on('callStateChange', (data: observer.CallStateInfo) => {
  2. console.info("on callStateChange, data:" + JSON.stringify(data));
  3. });

observer.on('callStateChange')

Phone23+Tablet23+Wearable23+

on(type: 'callStateChange', options: ObserverOptions, callback: Callback<CallStateInfo>): void

Registers an observer for call status change events. This API uses an asynchronous callback to return the execution result.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Call status change event. This field has a fixed value of callStateChange.
options ObserverOptions Yes Event subscription parameters.
callback Callback<CallStateInfo> Yes

Callback function used to return the call status information object.

The application can obtain the CallStateInfo object. In this object:

- Only state is accessible to third-party applications. - number is only accessible to system applications.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let options: observer.ObserverOptions = {
  2. slotId: 0
  3. }
  4. observer.on('callStateChange', options, (data: observer.CallStateInfo) => {
  5. console.info("on callStateChange, data:" + JSON.stringify(data));
  6. });

observer.off('callStateChange')

Phone23+Tablet23+Wearable23+

off(type: 'callStateChange', callback?: Callback<CallStateInfo>): void

Unregisters the observer for call status change events. This API uses an asynchronous callback to return the execution result.

NOTE

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.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Call status change event. This field has a fixed value of callStateChange.
callback Callback<CallStateInfo> No

Callback function used to return the call status information object. For details, see CallState.

number: phone number.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let callback: (data: observer.CallStateInfo) => void = (data: observer.CallStateInfo) => {
  2. console.info("on callStateChange, data:" + JSON.stringify(data));
  3. }
  4. observer.on('callStateChange', callback);
  5. // 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.
  6. observer.off('callStateChange', callback);
  7. observer.off('callStateChange');

observer.on('callStateChangeEx')21+

Phone23+Tablet23+Wearable23+

on(type: 'callStateChangeEx', callback: Callback<TelCallState>, options?: ObserverOptions): void

Registers an observer for extended call status change events. This API uses an asynchronous callback to return the execution result.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Extended call status change event. This field has a fixed value of callStateChangeEx.
callback Callback<TelCallState> Yes

Callback function used to return the call status information object.

The application can obtain TelCallState.

options ObserverOptions No Event subscription parameters.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
8800001 Invalid parameter value.
8800002 Service connection failed.
8800003 System internal error.
8800999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { call } from '@kit.TelephonyKit';
  2. let callback: (data: call.TelCallState) => void = (data: call.TelCallState) => {
  3. console.info("on callStateChangeEx, data:" + JSON.stringify(data));
  4. }
  5. let options: observer.ObserverOptions = {
  6. slotId: 0
  7. }
  8. observer.on('callStateChangeEx', callback, options);
  9. observer.on('callStateChangeEx', callback);

observer.off('callStateChangeEx')21+

Phone23+Tablet23+Wearable23+

off(type: 'callStateChangeEx', callback?: Callback<TelCallState>): void

Unregisters the observer for extended call status change events. This API uses an asynchronous callback to return the execution result.

NOTE

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.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Call status change event. This field has a fixed value of callStateChange.
callback Callback<TelCallState> No

Callback function used to return the call status information object. For details, see TelCallState in call.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
8800001 Invalid parameter value.
8800002 Service connection failed.
8800003 System internal error.
8800999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { call } from '@kit.TelephonyKit';
  2. let callback: (data: call.TelCallState) => void = (data: call.TelCallState) => {
  3. console.info("on callStateChangeEx, data:" + JSON.stringify(data));
  4. }
  5. observer.on('callStateChangeEx', callback);
  6. // 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.
  7. observer.off('callStateChangeEx', callback);
  8. observer.off('callStateChangeEx');

observer.on('cellularDataConnectionStateChange')7+

Phone23+Tablet23+Wearable23+

on(type: 'cellularDataConnectionStateChange', callback: Callback<DataConnectionStateInfo>): void

Registers an observer for connection status change events of the cellular data link. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Cellular data connection status event. This field has a fixed value of cellularDataConnectionStateChange.
callback Callback<DataConnectionStateInfo> Yes Callback function used to return the cellular data connection status information object. For details, see DataConnectState of data and RadioTechnology of radio.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. observer.on('cellularDataConnectionStateChange', (data: observer.DataConnectionStateInfo) => {
  2. console.info("on cellularDataConnectionStateChange, data:" + JSON.stringify(data));
  3. });

observer.on('cellularDataConnectionStateChange')7+

Phone23+Tablet23+Wearable23+

on(type: 'cellularDataConnectionStateChange', options: ObserverOptions, callback: Callback<DataConnectionStateInfo>): void

Registers 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.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Cellular data connection status event. This field has a fixed value of cellularDataConnectionStateChange.
options ObserverOptions Yes Event subscription parameters.
callback Callback<DataConnectionStateInfo> Yes Callback function used to return the cellular data connection status information object. For details, see DataConnectState of data and RadioTechnology of radio.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let options: observer.ObserverOptions = {
  2. slotId: 0
  3. }
  4. observer.on('cellularDataConnectionStateChange', options, (data: observer.DataConnectionStateInfo) => {
  5. console.info("on cellularDataConnectionStateChange, data:" + JSON.stringify(data));
  6. });

observer.off('cellularDataConnectionStateChange')7+

Phone23+Tablet23+Wearable23+

off(type: 'cellularDataConnectionStateChange', callback?: Callback<DataConnectionStateInfo>): void

Unregisters the observer for connection status change events of the cellular data link. This API uses an asynchronous callback to return the result.

NOTE

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.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Cellular data connection status event. This field has a fixed value of cellularDataConnectionStateChange.
callback Callback<DataConnectionStateInfo> No Callback function used to return the cellular data connection status information object. For details, see DataConnectState of data and RadioTechnology of radio.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let callback: (data: observer.DataConnectionStateInfo) => void = (data: observer.DataConnectionStateInfo) => {
  2. console.info("on cellularDataConnectionStateChange, data:" + JSON.stringify(data));
  3. }
  4. observer.on('cellularDataConnectionStateChange', callback);
  5. // 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.
  6. observer.off('cellularDataConnectionStateChange', callback);
  7. observer.off('cellularDataConnectionStateChange');

observer.on('cellularDataFlowChange')7+

Phone23+Tablet23+Wearable23+

on(type: 'cellularDataFlowChange', callback: Callback<DataFlowType>): void

Registers 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.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Cellular data flow change event. This field has a fixed value of cellularDataFlowChange.
callback Callback<DataFlowType> Yes Callback function used to return the data flow status object. For details, see DataFlowType in data.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { data } from '@kit.TelephonyKit';
  2. observer.on('cellularDataFlowChange', (data: data.DataFlowType) => {
  3. console.info("on cellularDataFlowChange, data:" + JSON.stringify(data));
  4. });

observer.on('cellularDataFlowChange')7+

Phone23+Tablet23+Wearable23+

on(type: 'cellularDataFlowChange', options: ObserverOptions, callback: Callback<DataFlowType>): void

Registers 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.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Cellular data flow change event. This field has a fixed value of cellularDataFlowChange.
options ObserverOptions Yes Event subscription parameters.
callback Callback<DataFlowType> Yes Callback function used to return the data flow status object. For details, see DataFlowType in data.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { data } from '@kit.TelephonyKit';
  2. let options: observer.ObserverOptions = {
  3. slotId: 0
  4. }
  5. observer.on('cellularDataFlowChange', options, (data: data.DataFlowType) => {
  6. console.info("on cellularDataFlowChange, data:" + JSON.stringify(data));
  7. });

observer.off('cellularDataFlowChange')7+

Phone23+Tablet23+Wearable23+

off(type: 'cellularDataFlowChange', callback?: Callback<DataFlowType>): void

Unregisters 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.

NOTE

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.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Cellular data flow change event. This field has a fixed value of cellularDataFlowChange.
callback Callback<DataFlowType> No Callback function used to return the data flow status object. For details, see DataFlowType in data.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { data } from '@kit.TelephonyKit';
  2. let callback: (data: data.DataFlowType) => void = (data: data.DataFlowType) => {
  3. console.info("on cellularDataFlowChange, data:" + JSON.stringify(data));
  4. }
  5. observer.on('cellularDataFlowChange', callback);
  6. // 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.
  7. observer.off('cellularDataFlowChange', callback);
  8. observer.off('cellularDataFlowChange');

observer.on('simStateChange')7+

Phone23+Tablet23+Wearable23+

on(type: 'simStateChange', callback: Callback<SimStateData>): void

Registers an observer for SIM card status change events. This API uses an asynchronous callback to return the result.

NOTE

The return result of this API does not contain the activation status of the SIM card. For details, see sim.isSimActive.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes SIM status change event. This field has a fixed value of simStateChange.
callback Callback<SimStateData> Yes Callback function used to return the SIM status data object.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. observer.on('simStateChange', (data: observer.SimStateData) => {
  2. console.info("on simStateChange, data:" + JSON.stringify(data));
  3. });

observer.on('simStateChange')7+

Phone23+Tablet23+Wearable23+

on(type: 'simStateChange', options: ObserverOptions, callback: Callback<SimStateData>): void

Registers an observer for status change events of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes SIM status change event. This field has a fixed value of simStateChange.
options ObserverOptions Yes Event subscription parameters.
callback Callback<SimStateData> Yes Callback function used to return the SIM status data object.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let options: observer.ObserverOptions = {
  2. slotId: 0
  3. }
  4. observer.on('simStateChange', options, (data: observer.SimStateData) => {
  5. console.info("on simStateChange, data:" + JSON.stringify(data));
  6. });

observer.off('simStateChange')7+

Phone23+Tablet23+Wearable23+

off(type: 'simStateChange', callback?: Callback<SimStateData>): void

Unregisters the observer for SIM card status change events. This API uses an asynchronous callback to return the result.

NOTE

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.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes SIM status change event. This field has a fixed value of simStateChange.
callback Callback<SimStateData> No Callback function used to return the SIM status data object.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let callback: (data: observer.SimStateData) => void = (data: observer.SimStateData) => {
  2. console.info("on simStateChange, data:" + JSON.stringify(data));
  3. }
  4. observer.on('simStateChange', callback);
  5. // 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.
  6. observer.off('simStateChange', callback);
  7. observer.off('simStateChange');

observer.on('iccAccountInfoChange')10+

Phone23+Tablet23+Wearable23+

on(type: 'iccAccountInfoChange', callback: Callback<void>): void

Registers an observer for account information change events of the SIM card. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Account information change event. This field has a fixed value of iccAccountInfoChange.
callback Callback<void> Yes Callback used to return the result. If the account is successfully changed, the value of err is undefined. Otherwise, the value is an error object.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. observer.on('iccAccountInfoChange', () => {
  2. console.info("on iccAccountInfoChange success");
  3. });

observer.off('iccAccountInfoChange')10+

Phone23+Tablet23+Wearable23+

off(type: 'iccAccountInfoChange', callback?: Callback<void>): void

Unregisters the observer for account information change events of the SIM card. This API uses an asynchronous callback to return the result.

NOTE

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.

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
type string Yes Account information change event. This field has a fixed value of iccAccountInfoChange.
callback Callback<void> No Callback used to return the result. If the account is successfully changed, the value of err is undefined. Otherwise, the value is an error object.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let callback: () => void = () => {
  2. console.info("on iccAccountInfoChange success");
  3. }
  4. observer.on('iccAccountInfoChange', callback);
  5. // 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.
  6. observer.off('iccAccountInfoChange', callback);
  7. observer.off('iccAccountInfoChange');

observer.onGetSimActiveState23+

Phone23+Tablet23+Wearable23+

onGetSimActiveState(slotId: number, callback: Callback<boolean>): void

Registers an observer for SIM card activation state changes. This API uses an asynchronous callback to return the execution result.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
slotId number Yes

Card slot ID.

- 0: card slot 1.

- 1: card slot 2.

callback Callback<boolean> Yes

Callback function used to return whether the SIM card is activated.

- true: activated.

- false: not activated.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
201 Permission denied
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. import { sim } from '@kit.TelephonyKit';
  3. let sislotId = 0;
  4. let simActiveState: Callback<boolean> = (isSimActive: boolean) => {
  5. console.info(`simActiveState slotId ${JSON.stringify(isSimActive)}`);
  6. }
  7. observer.onGetSimActiveState(sislotId, simActiveState);

observer.offGetSimActiveState23+

Phone23+Tablet23+Wearable23+

offGetSimActiveState(callback?: Callback<boolean>): void

Unregisters an observer for SIM card activation state changes. This API uses an asynchronous callback to return the execution result.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.StateRegistry

Parameters

Expand
Name Type Mandatory Description
callback Callback<boolean> No

Callback function used to return whether the SIM card is activated.

- true: activated.

- false: not activated.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
201 Permission denied
8300001 Invalid parameter value.
8300002 Service connection failed.
8300003 System internal error.
8300999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. import { sim } from '@kit.TelephonyKit';
  3. let simActiveState: Callback<boolean> = (isSimActive: boolean) => {
  4. console.info(`simActiveState slotId ${JSON.stringify(isSimActive)}`);
  5. }
  6. observer.offGetSimActiveState(simActiveState);

observer.onCCallStateChange23+

Phone23+Tablet23+Wearable23+

onCCallStateChange(callback: Callback<CCallStateInfo>, options?: ObserverOptions): void

Subscribes to the carrier call state changes and obtains the call number. This method uses an asynchronous callback to return the execution result.

System capability: SystemCapability.Telephony.StateRegistry

Required permissions: ohos.permission.MANAGE_CALL_FOR_DEVICES

Parameters

Expand
Name Type Mandatory Description
callback Callback<CCallStateInfo> Yes

Callback function used to return the call status information object.

The application can obtain CCallState.

options ObserverOptions No Event subscription parameters.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
201 Permission denied
8800001 Invalid parameter value.
8800002 Service connection failed.
8800003 System internal error.
8800999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { call, observer } from '@kit.TelephonyKit';
  2. let callback: (data: observer.CCallStateInfo) => void = (data: observer.CCallStateInfo) => {
  3. console.info("onCCallStateChange, data:" + JSON.stringify(data));
  4. }
  5. let options: observer.ObserverOptions = {
  6. slotId: 0
  7. }
  8. observer.onCCallStateChange(callback, options);
  9. observer.onCCallStateChange(callback);

observer.offCCallStateChange23+

Phone23+Tablet23+Wearable23+

offCCallStateChange(callback?: Callback<CCallStateInfo>): void

Cancels the listening on the carrier call status and obtaining of the call number by a third-party application. This method uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.StateRegistry

Required permissions: ohos.permission.MANAGE_CALL_FOR_DEVICES

Parameters

Expand
Name Type Mandatory Description
callback Callback<CCallStateInfo> No

Callback function used to return the call status information object.

The application can obtain CCallState.

Error codes

For details about the error codes, see Universal Error Codes and Telephony Error Codes.

Expand
ID Error Message
201 Permission denied
8800001 Invalid parameter value.
8800002 Service connection failed.
8800003 System internal error.
8800999 Unknown error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { call, observer } from '@kit.TelephonyKit';
  2. let callback: (data: observer.CCallStateInfo) => void = (data: observer.CCallStateInfo) => {
  3. console.info("onCCallStateChange, data:" + JSON.stringify(data));
  4. }
  5. observer.offCCallStateChange(callback);
  6. observer.offCCallStateChange();

LockReason8+

Phone23+Tablet23+Wearable23+

Enumerates SIM card lock types.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Name Value Description
SIM_NONE 0 No lock.
SIM_PIN 1 PIN lock.
SIM_PUK 2 PUK lock.
SIM_PN_PIN 3 Network PIN lock.
SIM_PN_PUK 4 Network PUK lock.
SIM_PU_PIN 5 Subnet PIN lock.
SIM_PU_PUK 6 Subnet PUK lock.
SIM_PP_PIN 7 Service provider PIN lock.
SIM_PP_PUK 8 Service provider PUK lock.
SIM_PC_PIN 9 Organization PIN lock.
SIM_PC_PUK 10 Organization PUK lock.
SIM_SIM_PIN 11 SIM PIN lock.
SIM_SIM_PUK 12 SIM PUK lock.

SimStateData7+

Phone23+Tablet23+Wearable23+

Enumerates SIM card types and states.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Name Type Read-Only Optional Description
type CardType No No SIM card type.
state SimState No No SIM card state.
reason8+ LockReason No No SIM card lock type.

CallStateInfo11+

Phone23+Tablet23+Wearable23+

Defines information about the call status.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Name Type Read-Only Optional Description
state CallState No No Call type.
number string No No Phone number.

CCallStateInfo23+

Phone23+Tablet23+Wearable23+

Defines information about the call status.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Name Type Read-Only Optional Description
state CCallState No No Call type.
teleNumber string No No Phone number.

DataConnectionStateInfo11+

Phone23+Tablet23+Wearable23+

Defines information about the data connection status.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Name Type Read-Only Optional Description
state DataConnectState No No Data connection status.
network RatType No No Network type.

ObserverOptions11+

Phone23+Tablet23+Wearable23+

Defines event subscription parameters.

System capability: SystemCapability.Telephony.StateRegistry

Expand
Name Type Read-Only Optional Description
slotId number No No

Card slot ID.

- 0: card slot 1.

- 1: card slot 2.

Search in References
Enter a keyword.