提交 d942f07b 编写于 作者: G geraltxu

异步接口整改文档修改

Signed-off-by: Nxufanghan <xufanghan@huawei.com>
上级 ef4ad868
......@@ -21,9 +21,12 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
| function queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback&lt;Array&lt;BundleStatsInfo&gt;&gt;): void | 通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息。 |
| function queryAppGroup(callback: AsyncCallback&lt;number&gt;): void | 查询当前应用的使用优先级群组。callback形式。 |
| function queryAppGroup(): Promise&lt;number&gt;; | 查询当前应用的使用优先级群组。promise形式。 |
|function queryAppGroupSync(): number; | 查询当前应用的使用优先级群组。同步接口。|
| function queryAppGroup(bundleName : string, callback: AsyncCallback&lt;number&gt;): void | 查询指定应用的使用优先级群组。callback形式。 |
| function queryAppGroup(bundleName : string): Promise&lt;number&gt;; | 查询当前调用者应用或者指定应用的使用优先级群组。promise形式。 |
|function queryAppGroupSync(bundleName: string): number; | 查询当前调用者应用或者指定应用的使用优先级群组。同步接口。|
| function isIdleState(bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void | 判断指定Bundle Name的应用当前是否是空闲状态。 |
|function isIdleStateSync(bundleName: string): boolean; | 判断指定Bundle Name的应用当前是否是空闲状态,同步接口。 |
| function queryModuleUsageRecords(callback: AsyncCallback&lt;HapModuleInfo&gt;): void | 查询FA使用记录,返回不超过1000条FA使用记录。 |
| function queryModuleUsageRecords(maxNum: number, callback: AsyncCallback&lt;HapModuleInfo&gt;): void | 根据maxNum,查询FA使用记录,返回不超过maxNum条FA使用记录。 maxNum不超过1000|
| function queryNotificationEventStats(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;DeviceEventStats&gt;&gt;): void | 通过指定起始和结束时间查询所有应用的通知次数。 |
......@@ -225,6 +228,14 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
} catch (error) {
console.log('BUNDLE_ACTIVE queryAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message);
}
//同步方式
try{
var priorityGroup = usageStatistics.queryAppGroupSync();
} catch (error) {
console.log('BUNDLE_ACTIVE queryAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message);
}
```
7. 判断指定Bundle Name的应用当前是否是空闲状态,需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限。
......@@ -255,6 +266,13 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
} catch(error) {
console.log('BUNDLE_ACTIVE isIdleState throw error, code is: ' + error.code + ',message is: ' + error.message);
}
//同步方式
try{
var isIdleState = usageStatistics.isIdleStateSync("com.ohos.camera");
} catch(error) {
console.log('BUNDLE_ACTIVE isIdleState throw error, code is: ' + error.code + ',message is: ' + error.message);
}
```
8. 查询FA使用记录。返回数量最大不超过maxNum设置的值,若不传入maxNum参数,则默认maxNum为1000, 需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限。
......
......@@ -31,7 +31,102 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics'
## usageStatistics.isIdleState
isIdleState(bundleName: string): boolean
isIdleState(bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void
判断指定bundleName的应用当前是否是空闲状态,三方应用只能查询自身的空闲状态,使用Callback形式返回。
**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
**系统API**:此接口为系统接口。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ---------------------------- | ---- | ---------------------------------------- |
| bundleName | string | 是 | 应用的bundleName。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 指定的callback回调方法。如果指定的bundleName有效,则返回指定bundleName的应用当前是否是空闲状态;否则返回null。 |
**错误码**
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
| 错误码ID | 错误信息 |
| ---------- | ---------------------------- |
| 10000001 | Memory operation failed. |
| 10000002 | Parcel operation failed. |
| 10000003 | System service operation failed. |
| 10000004 | IPC failed. |
| 10000006 | Failed to get the application information. |
**示例**
```js
try{
usageStatistics.isIdleState("com.ohos.camera", (err, res) => {
if (err) {
console.log('BUNDLE_ACTIVE isIdleState callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
}
});
} catch(error) {
console.log('BUNDLE_ACTIVE isIdleState throw error, code is: ' + error.code + ',message is: ' + error.message);
}
```
## usageStatistics.isIdleState
isIdleState(bundleName: string): Promise&lt;boolean&gt;
判断指定bundleName的应用当前是否是空闲状态,三方应用只能查询自身的空闲状态,使用Promise形式返回。
**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
**系统API**:此接口为系统接口。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------ | ---- | -------------- |
| bundleName | string | 是 | 应用的bundleName。 |
**返回值**
| 类型 | 说明 |
| ---------------------- | ---------------------------------------- |
| Promise&lt;boolean&gt; | 指定的Promise回调方法。如果指定的bundleName有效,则返回指定bundleName的应用当前是否是空闲状态;否则返回null。 |
**错误码**
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
| 错误码ID | 错误信息 |
| ---------- | ---------------------------- |
| 10000001 | Memory operation failed. |
| 10000002 | Parcel operation failed. |
| 10000003 | System service operation failed. |
| 10000004 | IPC failed. |
| 10000006 | Failed to get the application information. |
**示例**
```js
try{
usageStatistics.isIdleState("com.ohos.camera").then( res => {
console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res));
}).catch( err => {
console.log('BUNDLE_ACTIVE isIdleState promise failed. code is: ' + err.code + ',message is: ' + err.message);
});
} catch (error) {
console.log('BUNDLE_ACTIVE isIdleState throw error, code is: ' + error.code + ',message is: ' + error.message);
}
```
## usageStatistics.isIdleStateSync<sup>10+<sup>
isIdleStateSync(bundleName: string): boolean
判断指定bundleName的应用当前是否是空闲状态,三方应用只能查询自身的空闲状态。
......@@ -51,7 +146,7 @@ isIdleState(bundleName: string): boolean
| 类型 | 说明 |
| ---------------------- | ---------------------------------------- |
| boolean | 如果指定的bundleName有效,则返回指定bundleName的应用当前是否是空闲状态。 |
| boolean | 如果指定的bundleName有效,返回true则表示空闲状态,false则非空闲。 |
**错误码**
......@@ -68,7 +163,7 @@ isIdleState(bundleName: string): boolean
**示例**
```js
try{
var isIdleState = usageStatistics.isIdleState("com.ohos.camera");
var isIdleState = usageStatistics.isIdleStateSync("com.ohos.camera");
} catch(error) {
console.log('BUNDLE_ACTIVE isIdleState throw error, code is: ' + error.code + ',message is: ' + error.message);
}
......@@ -76,9 +171,9 @@ isIdleState(bundleName: string): boolean
## usageStatistics.queryAppGroup
queryAppGroup(): number;
queryAppGroup(): Promise&lt;number&gt;
查询当前应用的优先级分组。返回其应用分组。
查询当前应用的优先级分组。使用Promise形式返回其应用分组。
**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
......@@ -88,7 +183,7 @@ queryAppGroup(): number;
| 类型 | 说明 |
| --------------- | --------------------------- |
| number | 返回查询的应用分组结果。 |
| Promise&lt;number&gt; | 指定的Promise回调方法。返回查询的应用分组结果。 |
**错误码**
......@@ -108,7 +203,11 @@ queryAppGroup(): number;
```javascript
try{
var priorityGroup = usageStatistics.queryAppGroup();
usageStatistics.queryAppGroup().then( res => {
console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch( err => {
console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
});
} catch (error) {
console.log('BUNDLE_ACTIVE queryAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message);
}
......@@ -116,9 +215,95 @@ queryAppGroup(): number;
## usageStatistics.queryAppGroup
queryAppGroup(bundleName: string): number
queryAppGroup(callback: AsyncCallback&lt;number&gt;): void
查询当前应用的优先级分组。使用callback形式返回其应用分组。
**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
**系统API**:此接口为系统接口。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------- | ---- | -------------------------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 指定的CallBack回调方法。返回查询的应用分组。 |
**错误码**
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
| 错误码ID | 错误信息 |
| ---------- | ---------------------------- |
| 10000001 | Memory operation failed. |
| 10000002 | Parcel operation failed. |
| 10000003 | System service operation failed. |
| 10000004 | IPC failed. |
| 10000005 | Application is not installed. |
| 10000006 | Failed to get the application information. |
| 10100002 | Failed to get the application group information. |
**示例**
```javascript
try{
usageStatistics.queryAppGroup((err, res) => {
if(err) {
console.log('BUNDLE_ACTIVE queryAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('BUNDLE_ACTIVE queryAppGroup callback succeeded. result: ' + JSON.stringify(res));
}
});
} catch (error) {
console.log('BUNDLE_ACTIVE queryAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message);
}
```
## usageStatistics.queryAppGroupSync<sup>10+<sup>
queryAppGroupSync(): number;
查询当前应用的优先级分组。
**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
**系统API**:此接口为系统接口。
**返回值**
| 类型 | 说明 |
| --------------- | --------------------------- |
| number | 返回当前应用优先级分组结果。 |
**错误码**
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
| 错误码ID | 错误信息 |
| ---------- | ---------------------------- |
| 10000001 | Memory operation failed. |
| 10000002 | Parcel operation failed. |
| 10000003 | System service operation failed. |
| 10000004 | IPC failed. |
| 10000005 | Application is not installed. |
| 10000006 | Failed to get the application information. |
| 10100002 | Failed to get the application group information. |
**示例**
```javascript
try{
var priorityGroup = usageStatistics.queryAppGroupSync();
} catch (error) {
console.log('BUNDLE_ACTIVE queryAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message);
}
```
## usageStatistics.queryAppGroupSync<sup>10+<sup>
queryAppGroupSync(bundleName: string): number
查询指定应用的优先级分组。返回其应用分组。
查询指定bundleName应用的优先级分组。
**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
......@@ -134,7 +319,7 @@ queryAppGroup(bundleName: string): number
| 类型 | 说明 |
| --------------- | --------------------------- |
| number | 返回查询的应用分组结果。 |
| number | 返回指定bundleName应用优先级分组结果。 |
**错误码**
......@@ -154,7 +339,7 @@ queryAppGroup(bundleName: string): number
```javascript
try{
var priorityGroup = usageStatistics.queryAppGroup("com.ohos.camera");
var priorityGroup = usageStatistics.queryAppGroupSync("com.ohos.camera");
} catch (error) {
console.log('BUNDLE_ACTIVE queryAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册