同步操作将从 OpenHarmony/telephony_cellular_data 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
The cellular data module is a tailorable component of the Telephony subsystem. It depends on the telephony core service (core_service) and RIL Adapter (ril_adapter). The module provides functions such as cellular data activation, cellular data fault detection and rectification, cellular data status management, cellular data switch management, cellular data roaming management, APN management, and network management and interaction.
Figure 1 Architecture of the cellular data module
base/telephony/cellular_data/
├── figures
├── frameworks
│ ├── js
│ │ └── napi
│ │ ├── include # js head files
│ │ └── src # js source files
│ └── native
├── interfaces # externally exposed interface
│ ├── innerkits
│ └── kits
│ └── js
│ └── declaration # external JS API interfaces
├── sa_profile # SA profiles
├── services
│ ├── include # head files
│ │ ├── apn_manager
│ │ ├── common
│ │ ├── state_machine
│ │ └── utils
│ └── src # source files
│ ├── apn_manager
│ ├── state_machine
│ └── utils
└── test
└── unit_test # unit test code
Table 1 External APIs provided by the cellular data module
API | Description | Required Permission |
---|---|---|
function isCellularDataEnabled(callback: AsyncCallback<boolean>): void; | Checks whether the cellular data is enabled | ohos.permission.GET_NETWORK_INFO |
function getCellularDataState(callback: AsyncCallback<DataConnectState>): void; | Obtains the cellular data status. | ohos.permission.GET_NETWORK_INFO |
Call the IsCellularDataEnabled method in callback or Promise mode to check whether the cellular data is enabled.
This method works in asynchronous mode. The execution result is returned through the callback.
import data from "@ohos.telephony.data";
// Call the API in callback mode.
data.isCellularDataEnabled((err, value) => {
if (err) {
// If the API call failed, err is not empty.
console.error(`failed to isCellularDataEnabled because ${err.message}`);
return;
}
// If the API call succeeded, err is empty.
console.log(`success to isCellularDataEnabled: ${value}`);
});
// Call the API in Promise mode.
let promise = data.isCellularDataEnabled();
promise.then((value) => {
// The API call succeeded.
console.log(`success to isCellularDataEnabled: ${value}`);
}).catch((err) => {
// The API call failed.
console.error(`failed to isCellularDataEnabled because ${err.message}`);
});
Table 2 Description of DataConnectState enum values
Name | ValueDescription | |
---|---|---|
DATA_STATE_UNKNOWN | -1 | Unknown |
DATA_STATE_DISCONNECTED | 0 | Disconnected |
DATA_STATE_CONNECTING | 1 | Connecting |
DATA_STATE_CONNECTED | 2 | Connected |
DATA_STATE_SUSPENDED | 3 | Suspended |
Call the getCellularDataState method in callback or Promise mode to obtain the cellular data status.
This method works in asynchronous mode. The execution result is returned through the callback.
import data from "@ohos.telephony.data";
// Call the API in callback mode.
data.getCellularDataState((err, value) => {
if (err) {
// If the API call failed, err is not empty.
console.error(`failed to getCellularDataState because ${err.message}`);
return;
}
// If the API call succeeded, err is empty.
console.log(`success to getCellularDataState: ${value}`);
});
// Call the API in Promise mode.
let promise = data.getCellularDataState();
promise.then((value) => {
// The API call succeeded.
console.log(`success to getCellularDataState: ${value}`);
}).catch((err) => {
// The API call failed.
console.error(`failed to getCellularDataState because ${err.message}`);
});
Telephony
telephony_cellular_data
telephony_core_service
telephony_ril_adapter
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。