mirror of
https://gitee.com/openharmony/telephony_cellular_data
synced 2024-11-26 17:40:49 +00:00
新增检查移动数据、数据漫游是否启用的接口文档
Signed-off-by: 暮雨清风 <wuyvfeng05@chinasoftinc.com>
This commit is contained in:
parent
faac88b242
commit
396759fbc2
53
README.md
53
README.md
@ -7,7 +7,9 @@
|
||||
- [Usage Guidelines](#section160mcpsimp)
|
||||
- [Checking the Cellular Data Status](#section192mcpsimp)
|
||||
- [Obtaining the Cellular Data Status](#section213mcpsimp)
|
||||
|
||||
- [Check if cellular mobile data service is enabled](#section234mcpsimp)
|
||||
- [Check if cellular data roaming is enabled](#section255mcpsimp)
|
||||
|
||||
- [Repositories Involved](#section234mcpsimp)
|
||||
|
||||
## Introduction<a name="section117mcpsimp"></a>
|
||||
@ -61,10 +63,12 @@ base/telephony/cellular_data/
|
||||
|
||||
<a name="table133mcpsimp"></a>
|
||||
|
||||
| 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 |
|
||||
| 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 |
|
||||
| function isCellularDataEnabledSync(): boolean; | Checks if cellular mobile data service is enabled. | ohos.permission.GET_NETWORK_INFO |
|
||||
| function isCellularDataRoamingEnabledSync(slotId: number): boolean; | Checks if cellular data roaming is enabled(The parameter slotId is the SIM card id, 0 represents card one, and 1 represents card two). | ohos.permission.GET_NETWORK_INFO |
|
||||
|
||||
|
||||
## Usage Guidelines<a name="section160mcpsimp"></a>
|
||||
@ -99,6 +103,45 @@ base/telephony/cellular_data/
|
||||
});
|
||||
```
|
||||
|
||||
### Check if cellular mobile data service is enabled<a name="section234mcpsimp"></a>
|
||||
|
||||
1. You can determine if cellular data services are enabled by calling isCellularDataEnabledSync.
|
||||
|
||||
2. This interface is synchronous, and the relevant execution results will be returned from isCellularDataEnabledSync.
|
||||
|
||||
```
|
||||
import data from "@ohos.telephony.data";
|
||||
|
||||
try {
|
||||
// Call the interface [Sync method]
|
||||
let isEnabled: boolean = data.isCellularDataEnabledSync();
|
||||
// Call the interface successfully
|
||||
console.log(`isCellularDataEnabledSync success : ${isEnabled}`);
|
||||
} catch (error) {
|
||||
// Call the interface failed
|
||||
console.log(`isCellularDataEnabledSync failed`);
|
||||
}
|
||||
```
|
||||
|
||||
### Check if cellular data roaming is enabled<a name="section255mcpsimp"></a>
|
||||
|
||||
1. You can determine if cellular data roaming services are enabled by calling isCellularDataRoamingEnabledSync.
|
||||
|
||||
2. This interface is synchronous, and the relevant execution results will be returned from isCellularDataRoamingEnabledSync.
|
||||
|
||||
```
|
||||
import data from "@ohos.telephony.data";
|
||||
|
||||
try {
|
||||
// Call the interface [Sync method]
|
||||
let isEnabled: boolean = data.isCellularDataRoamingEnabledSync(0);
|
||||
// Call the interface successfully
|
||||
console.log(`isCellularDataRoamingEnabledSync success : ${isEnabled}`);
|
||||
} catch (error) {
|
||||
// Call the interface failed
|
||||
console.log(`isCellularDataRoamingEnabledSync failed`);
|
||||
}
|
||||
```
|
||||
|
||||
### Obtaining the Cellular Data Status<a name="section213mcpsimp"></a>
|
||||
|
||||
|
56
README_zh.md
56
README_zh.md
@ -7,7 +7,10 @@
|
||||
- [使用说明](#section160mcpsimp)
|
||||
- [获取蜂窝数据开关是否打开](#section192mcpsimp)
|
||||
- [获取蜂窝数据状态](#section213mcpsimp)
|
||||
|
||||
- [获取蜂窝移动数据是否启用](#section234mcpsimp)
|
||||
|
||||
[获取蜂窝数据漫游是否启用](#section255mcpsimp)
|
||||
|
||||
- [相关仓](#section234mcpsimp)
|
||||
|
||||
## 简介<a name="section117mcpsimp"></a>
|
||||
@ -51,10 +54,12 @@ base/telephony/cellular_data/
|
||||
|
||||
<a name="table133mcpsimp"></a>
|
||||
|
||||
| 接口名称 | 接口描述 | 所需权限 |
|
||||
| ------------------------------------------------------------ | ------------------------ | -------------------------------- |
|
||||
| function isCellularDataEnabled(callback: AsyncCallback\<boolean>): void; | 获取蜂窝数据开关是否打开 | ohos.permission.GET_NETWORK_INFO |
|
||||
| function getCellularDataState(callback: AsyncCallback\<DataConnectState>): void; | 获取蜂窝数据状态 | ohos.permission.GET_NETWORK_INFO |
|
||||
| 接口名称 | 接口描述 | 所需权限 |
|
||||
| ------------------------------------------------------------ | ------------------------------------------------------------ | -------------------------------- |
|
||||
| function isCellularDataEnabled(callback: AsyncCallback\<boolean>): void; | 获取蜂窝数据开关是否打开 | ohos.permission.GET_NETWORK_INFO |
|
||||
| function getCellularDataState(callback: AsyncCallback\<DataConnectState>): void; | 获取蜂窝数据状态 | ohos.permission.GET_NETWORK_INFO |
|
||||
| function isCellularDataEnabledSync(): boolean; | 获取蜂窝移动数据服务是否启用 | ohos.permission.GET_NETWORK_INFO |
|
||||
| function isCellularDataRoamingEnabledSync(slotId: number): boolean; | 获取蜂窝数据漫游服务是否启用(参数slotId为SIM卡id,0表示卡一,1表示卡二) | ohos.permission.GET_NETWORK_INFO |
|
||||
|
||||
完整的JS API说明以及实例代码请参考:[蜂窝数据](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-telephony-kit/js-apis-telephony-data.md)。
|
||||
|
||||
@ -62,12 +67,12 @@ base/telephony/cellular_data/
|
||||
|
||||
### 获取蜂窝数据开关是否打开<a name="section192mcpsimp"></a>
|
||||
|
||||
1. 可以通过callback或者Promise的方式调用IsCellularDataEnabled获取蜂窝数据开关是否打开。
|
||||
1. 可以通过callback或者Promise的方式调用isCellularDataEnabled获取蜂窝数据开关是否打开。
|
||||
2. 该接口为异步接口,相关执行结果会从callback中返回。
|
||||
|
||||
```
|
||||
import data from "@ohos.telephony.data";
|
||||
|
||||
|
||||
// 调用接口【callback方式】
|
||||
data.isCellularDataEnabled((err, value) => {
|
||||
if (err) {
|
||||
@ -90,6 +95,43 @@ base/telephony/cellular_data/
|
||||
});
|
||||
```
|
||||
|
||||
### 获取蜂窝移动数据服务是否启用<a name="section234mcpsimp"></a>
|
||||
|
||||
1. 可以通过调用isCellularDataEnabledSync获取蜂窝移动数据服务是否启用。
|
||||
2. 该接口为同步接口,相关执行结果会从isCellularDataEnabledSync中返回。
|
||||
|
||||
```
|
||||
import data from "@ohos.telephony.data";
|
||||
|
||||
try {
|
||||
// 调用接口【Sync方式】
|
||||
let isEnabled: boolean = data.isCellularDataEnabledSync();
|
||||
// 调用接口成功
|
||||
console.log(`isCellularDataEnabledSync success : ${isEnabled}`);
|
||||
} catch (error) {
|
||||
// 调用接口失败
|
||||
console.log(`isCellularDataEnabledSync failed`);
|
||||
}
|
||||
```
|
||||
|
||||
### 获取蜂窝数据漫游服务是否启用<a name="section255mcpsimp"></a>
|
||||
|
||||
1. 可以通过调用isCellularDataRoamingEnabledSync获取蜂窝数据漫游服务是否启用。
|
||||
2. 该接口为同步接口,相关执行结果会从isCellularDataRoamingEnabledSync中返回。
|
||||
|
||||
```
|
||||
import data from "@ohos.telephony.data";
|
||||
|
||||
try {
|
||||
// 调用接口【Sync方式】
|
||||
let isEnabled: boolean = data.isCellularDataRoamingEnabledSync(0);
|
||||
// 调用接口成功
|
||||
console.log(`isCellularDataRoamingEnabledSync success : ${isEnabled}`);
|
||||
} catch (error) {
|
||||
// 调用接口失败
|
||||
console.log(`isCellularDataRoamingEnabledSync failed`);
|
||||
}
|
||||
```
|
||||
|
||||
### 获取蜂窝数据状态<a name="section213mcpsimp"></a>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user