Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
3f65e220
D
Docs
项目概览
OpenHarmony
/
Docs
12 个月 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3f65e220
编写于
10月 28, 2022
作者:
Y
yupeng74@huawei.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
device仓文档信息修改
Signed-off-by:
N
yupeng74@huawei.com
<
yupeng74@huawei.com
>
上级
8bd3c0ef
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
157 addition
and
287 deletion
+157
-287
zh-cn/application-dev/device-usage-statistics/Readme-CN.md
zh-cn/application-dev/device-usage-statistics/Readme-CN.md
+1
-2
zh-cn/application-dev/device-usage-statistics/device-usage-statistics-dev-guide.md
...ice-usage-statistics/device-usage-statistics-dev-guide.md
+0
-128
zh-cn/application-dev/device-usage-statistics/device-usage-statistics-use-guide.md
...ice-usage-statistics/device-usage-statistics-use-guide.md
+73
-73
zh-cn/application-dev/reference/apis/js-apis-resourceschedule-deviceUsageStatistics.md
...ce/apis/js-apis-resourceschedule-deviceUsageStatistics.md
+83
-84
未找到文件。
zh-cn/application-dev/device-usage-statistics/Readme-CN.md
浏览文件 @
3f65e220
# 设备使用信息统计
-
[
设备使用信息统计概述
](
device-usage-statistics-overview.md
)
-
[
设备使用信息统计开发指导(API7)
](
device-usage-statistics-dev-guide.md
)
-
[
设备使用信息统计开发指导(API9)
](
device-usage-statistics-use-guide.md
)
\ No newline at end of file
-
[
设备使用信息统计开发指导
](
device-usage-statistics-use-guide.md
)
\ No newline at end of file
zh-cn/application-dev/device-usage-statistics/device-usage-statistics-dev-guide.md
已删除
100644 → 0
浏览文件 @
8bd3c0ef
# 设备使用信息统计(API7)
## 场景介绍
设备使用信息统计,包括app usage/notification usage/system usage等使用统计。例如应用使用信息统计,用于保存和查询应用使用详情(app usage)、事件日志数据(event log)、应用分组(bundle group)情况。
部件缓存的应用记录(使用历史统计和使用事件记录)会在事件上报后30分钟内刷新到数据库持久化保存。
根据设备的使用信息统计接口,开发者可以开发出健康管理类应用来实现个人设备健康使用功能,并向用户展示其个人设备的使用记录。
## 接口说明
注册相关接口包导入:
```
js
import
stats
from
'
@ohos.bundleState
'
;
```
**表1**
设备使用信息统计主要接口
| 接口名 | 描述 |
| -------- | -------- |
| function queryBundleActiveStates(begin: number, end: number, callback: AsyncCallback
<
Array
<
BundleActiveState
>>
): void | 通过指定起始和结束时间查询所有应用的事件集合。 |
| function queryBundleStateInfos(begin: number, end: number, callback: AsyncCallback
<
BundleActiveInfoResponse
>
): void | 通过指定起始和结束时间查询应用使用时长统计信息。 |
| function queryCurrentBundleActiveStates(begin: number, end: number, callback: AsyncCallback
<
Array
<
BundleActiveState
>>
): void | 通过指定起始和结束时间查询当前应用的事件集合。 |
| function queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback
<
Array
<
BundleStateInfo
>>
): void | 通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息。 |
| function queryAppUsagePriorityGroup(callback: AsyncCallback
<
number
>
): void | 查询当前应用的使用优先级群组。callback形式。 |
| function queryAppUsagePriorityGroup(): Promise
<
number
>
; | 查询当前应用的使用优先级群组。promise形式。 |
| function isIdleState(bundleName: string, callback: AsyncCallback
<
boolean
>
): void | 判断指定Bundle Name的应用当前是否是空闲状态。 |
## 开发步骤
1.
获取设备使用信息之前,需要检查是否已经配置请求相应的权限。
系统提供的设备使用信息统计的权限是ohos.permission.BUNDLE_ACTIVE_INFO
具体配置方式请参考
[
权限申请声明
](
../security/accesstoken-guidelines.md
)
2.
通过指定起始和结束时间查询所有应用的事件集合,需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限。
```js
import stats from '@ohos.bundleState'
stats.queryBundleActiveStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i]));
}
}).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code);
});
```
3.
通过指定起始和结束时间查询应用使用时长统计信息,需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限。
```js
import stats from '@ohos.bundleState'
stats.queryBundleStateInfos(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.');
let i = 1;
for (let key in res){
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key]));
i++;
}
}).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code);
});
```
4.
通过指定起始和结束时间查询当前应用的事件集合,不需要配置权限。
```js
import stats from '@ohos.bundleState'
stats.queryCurrentBundleActiveStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i]));
}
}).catch(err => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code);
});
```
5.
通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息,需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限。
```js
import stats from '@ohos.bundleState'
stats.queryBundleStateInfoByInterval(0, 0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i]));
}
}).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code);
});
```
6.
查询(无参)当前调用者应用的使用优先级群组,不需要配置权限。
```js
import stats from '@ohos.bundleState'
stats.queryAppUsagePriorityGroup().then(res => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch(err => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code);
});
```
7.
判断指定Bundle Name的应用当前是否是空闲状态,需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限,三方应用只能查询自身的空闲状态。
```js
import stats from '@ohos.bundleState'
stats.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, because: ' + err.code);
});
```
## 相关实例
针对设备使用信息统计,有以下相关实例可供参考:
-
[
`DeviceUsageStatistics`:设备使用信息统计(ArkTS)(API8)(Full SDK)
](
https://gitee.com/openharmony/applications_app_samples/tree/master/device/DeviceUsageStatistics
)
zh-cn/application-dev/device-usage-statistics/device-usage-statistics-use-guide.md
浏览文件 @
3f65e220
...
...
@@ -51,8 +51,8 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
usageStatistics.queryBundleEvents(0, 20000000000000).then( res => {
console.log('BUNDLE_ACTIVE queryBundleEvents promise success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleEvents promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleEvents promise result ' + JSON.stringify(res[i]));
console.log('BUNDLE_ACTIVE queryBundleEvents promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleEvents promise result ' + JSON.stringify(res[i]));
}
}).catch( err => {
console.log('BUNDLE_ACTIVE queryBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message);
...
...
@@ -65,9 +65,9 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
try{
usageStatistics.queryBundleEvents(0, 20000000000000, (err, res) => {
if (err) {
console.log('BUNDLE_ACTIVE queryBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message);
console.log('BUNDLE_ACTIVE queryBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('BUNDLE_ACTIVE queryBundleEvents callback success.');
console.log('BUNDLE_ACTIVE queryBundleEvents callback success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleEvents callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleEvents callback result ' + JSON.stringify(res[i]));
...
...
@@ -90,9 +90,9 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise success.');
let i = 1;
for(let key in res){
console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise result ' + JSON.stringify(res[key]));
i++;
console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise result ' + JSON.stringify(res[key]));
i++;
}
}).catch( err => {
console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise failed. code is: ' + err.code + ',message is: ' + err.message);
...
...
@@ -105,9 +105,9 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
try{
usageStatistics.queryBundleStatsInfos(0, 20000000000000, (err, res) => {
if (err) {
console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback failed. code is: ' + err.code + ',message is: ' + err.message);
console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback success.');
console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback success.');
let i = 1;
for(let key in res){
console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback number : ' + i);
...
...
@@ -131,8 +131,8 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
usageStatistics.queryCurrentBundleEvents(0, 20000000000000).then( res => {
console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise result ' + JSON.stringify(res[i]));
console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise result ' + JSON.stringify(res[i]));
}
}).catch( err => {
console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message);
...
...
@@ -145,9 +145,9 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
try{
usageStatistics.queryCurrentBundleEvents(0, 20000000000000, (err, res) => {
if (err) {
console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message);
console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback success.');
console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback result ' + JSON.stringify(res[i]));
...
...
@@ -169,8 +169,8 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000).then( res => {
console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise result ' + JSON.stringify(res[i]));
console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise result ' + JSON.stringify(res[i]));
}
}).catch( err => {
console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise failed. code is: ' + err.code + ',message is: ' + err.message);
...
...
@@ -183,9 +183,9 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
try{
usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000, (err, res) => {
if (err) {
console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback failed. code is: ' + err.code + ',message is: ' + err.message);
console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback success.');
console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback result ' + JSON.stringify(res[i]));
...
...
@@ -197,7 +197,7 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
}
```
6.
查询
(无参)当前调用者
应用的使用优先级群组,不需要配置权限。
6.
查询
当前
应用的使用优先级群组,不需要配置权限。
```js
import usageStatistics from '@ohos.resourceschedule.usageStatistics'
...
...
@@ -207,7 +207,7 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
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);
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);
...
...
@@ -216,11 +216,11 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
// callback方式
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));
}
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);
...
...
@@ -237,7 +237,7 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
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);
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);
...
...
@@ -246,11 +246,11 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
// 异步方法callback方式
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));
}
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);
...
...
@@ -271,7 +271,7 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i]));
}
}).catch( err=> {
console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message);
console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message);
});
} catch (error) {
console.log('BUNDLE_ACTIVE queryModuleUsageRecords throw error, code is: ' + error.code + ',message is: ' + error.message);
...
...
@@ -295,15 +295,15 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
// 异步方法callback方式
try{
usageStatistics.queryModuleUsageRecords(1000, (err, res) => {
if(err) {
console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i]));
if(err) {
console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i]));
}
}
}
});
} catch (error) {
console.log('BUNDLE_ACTIVE queryModuleUsageRecords throw error, code is: ' + error.code + ',message is: ' + error.message);
...
...
@@ -348,10 +348,10 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
try{
usageStatistics.queryNotificationEventStats(0, 20000000000000, (err, res) => {
if(err) {
console.log('BUNDLE_ACTIVE queryNotificationEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message);
console.log('BUNDLE_ACTIVE queryNotificationEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('BUNDLE_ACTIVE queryNotificationEventStats callback success.');
console.log('BUNDLE_ACTIVE queryNotificationEventStats callback result ' + JSON.stringify(res));
console.log('BUNDLE_ACTIVE queryNotificationEventStats callback success.');
console.log('BUNDLE_ACTIVE queryNotificationEventStats callback result ' + JSON.stringify(res));
}
});
} catch (error) {
...
...
@@ -380,10 +380,10 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
try{
usageStatistics.queryDeviceEventStats(0, 20000000000000, (err, res) => {
if(err) {
console.log('BUNDLE_ACTIVE queryDeviceEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message);
console.log('BUNDLE_ACTIVE queryDeviceEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('BUNDLE_ACTIVE queryDeviceEventStats callback success.');
console.log('BUNDLE_ACTIVE queryDeviceEventStats callback result ' + JSON.stringify(res));
console.log('BUNDLE_ACTIVE queryDeviceEventStats callback success.');
console.log('BUNDLE_ACTIVE queryDeviceEventStats callback result ' + JSON.stringify(res));
}
});
} catch (error) {
...
...
@@ -391,7 +391,7 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
}
```
11.
查询
(无参)当前调用者应用的使用优先级群组,config.json中不需要配置权限。查询(有参)指定应用的使用优先级群组
,需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限。
11.
查询
指定bundleName的应用的使用优先级群组,返回查询的优先级分组结果
,需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限。
```js
import usageStatistics from '@ohos.resourceschedule.usageStatistics'
...
...
@@ -402,28 +402,28 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
usageStatistics.queryAppGroup(bundleName).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);
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);
}
// 有bundleName异步方法callback方式
let bundleName = "com.ohos.camera";
let bundleName = "com.ohos.camera";
try{
usageStatistics.queryAppGroup(bundleName, (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));
}
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);
}
```
1
1.
给应用名是bundleName的应用分组设置成newGroup,返回设置结果是否成功,
需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限。
1
2.
给指定bundleName的应用的优先级分组设置成newGroup。
需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限。
```javascript
import usageStatistics from '@ohos.resourceschedule.usageStatistics'
...
...
@@ -436,7 +436,7 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
usageStatistics.setAppGroup(bundleName, newGroup).then( () => {
console.log('BUNDLE_ACTIVE setAppGroup promise succeeded.');
}).catch( err => {
console.log('BUNDLE_ACTIVE setAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
console.log('BUNDLE_ACTIVE setAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
});
} catch (error) {
console.log('BUNDLE_ACTIVE setAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message);
...
...
@@ -449,9 +449,9 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
try{
usageStatistics.setAppGroup(bundleName, newGroup, (err) => {
if(err) {
console.log('BUNDLE_ACTIVE setAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message);
console.log('BUNDLE_ACTIVE setAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('BUNDLE_ACTIVE setAppGroup callback succeeded.');
console.log('BUNDLE_ACTIVE setAppGroup callback succeeded.');
}
});
} catch (error) {
...
...
@@ -459,7 +459,7 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
}
```
1
2
.
注册应用分组变化监听回调,返回注册是否成功,当应用分组发生变化时,会给所有已注册的监听者返回回调信息, 需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限
1
3
.
注册应用分组变化监听回调,返回注册是否成功,当应用分组发生变化时,会给所有已注册的监听者返回回调信息, 需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限
```javascript
import usageStatistics from '@ohos.resourceschedule.usageStatistics'
...
...
@@ -477,7 +477,7 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
usageStatistics.registerAppGroupCallBack(onBundleGroupChanged).then( () => {
console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise succeeded.');
}).catch( err => {
console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message);
console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message);
});
} catch (error) {
console.log('BUNDLE_ACTIVE registerAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
...
...
@@ -493,8 +493,8 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName);
};
try{
usageStatistics.registerAppGroupCallBack(onBundleGroupChanged, err
or
=> {
if(err
or
) {
usageStatistics.registerAppGroupCallBack(onBundleGroupChanged, err => {
if(err) {
console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback success.');
...
...
@@ -505,33 +505,33 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics';
}
```
1
3.
解除应用分组监听回调, 需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限
1
4.
解除应用分组监听回调, 需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限。
```javascript
import usageStatistics from '@ohos.resourceschedule.usageStatistics'
// promise
try{
usageStatistics.un
R
egisterAppGroupCallBack().then( () => {
console.log('BUNDLE_ACTIVE un
R
egisterAppGroupCallBack promise succeeded.');
usageStatistics.un
r
egisterAppGroupCallBack().then( () => {
console.log('BUNDLE_ACTIVE un
r
egisterAppGroupCallBack promise succeeded.');
}).catch( err => {
console.log('BUNDLE_ACTIVE un
R
egisterAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message);
console.log('BUNDLE_ACTIVE un
r
egisterAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message);
});
} catch (error) {
console.log('BUNDLE_ACTIVE un
R
egisterAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
console.log('BUNDLE_ACTIVE un
r
egisterAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
}
// callback
try{
usageStatistics.un
RegisterAppGroupCallBack(erro
r => {
if(erro
r) {
console.log('BUNDLE_ACTIVE unR
egisterAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('BUNDLE_ACTIVE unR
egisterAppGroupCallBack callback success.');
}
usageStatistics.un
registerAppGroupCallBack(er
r => {
if(er
r) {
console.log('BUNDLE_ACTIVE unr
egisterAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('BUNDLE_ACTIVE unr
egisterAppGroupCallBack callback success.');
}
});
} catch (error) {
console.log('BUNDLE_ACTIVE un
R
egisterAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
console.log('BUNDLE_ACTIVE un
r
egisterAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
}
```
## 相关实例
...
...
zh-cn/application-dev/reference/apis/js-apis-resourceschedule-deviceUsageStatistics.md
浏览文件 @
3f65e220
...
...
@@ -57,15 +57,14 @@ isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void
| 10000006 | Get application info failed. |
**示例**
:
```
```
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));
}
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
);
...
...
@@ -111,7 +110,7 @@ isIdleState(bundleName: string): Promise<boolean>
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
);
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
);
...
...
@@ -193,11 +192,11 @@ queryAppGroup(callback: AsyncCallback<number>): void
```
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
));
}
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
);
...
...
@@ -243,15 +242,15 @@ queryBundleStatsInfos(begin: number, end: number, callback: AsyncCallback<Bun
try
{
usageStatistics
.
queryBundleStatsInfos
(
0
,
20000000000000
,
(
err
,
res
)
=>
{
if
(
err
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfos callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfos callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
}
else
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfos callback success.
'
);
let
i
=
1
;
for
(
let
key
in
res
){
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfos callback number :
'
+
i
);
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfos callback result
'
+
JSON
.
stringify
(
res
[
key
]));
i
++
;
}
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfos callback success.
'
);
let
i
=
1
;
for
(
let
key
in
res
){
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfos callback number :
'
+
i
);
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfos callback result
'
+
JSON
.
stringify
(
res
[
key
]));
i
++
;
}
}
});
}
catch
(
error
)
{
...
...
@@ -305,9 +304,9 @@ queryBundleStatsInfos(begin: number, end: number): Promise<BundleStatsMap>
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfos promise success.
'
);
let
i
=
1
;
for
(
let
key
in
res
){
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfos promise number :
'
+
i
);
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfos promise result
'
+
JSON
.
stringify
(
res
[
key
]));
i
++
;
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfos promise number :
'
+
i
);
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfos promise result
'
+
JSON
.
stringify
(
res
[
key
]));
i
++
;
}
}).
catch
(
err
=>
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfos promise failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
...
...
@@ -357,13 +356,13 @@ queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: num
try
{
usageStatistics
.
queryBundleStatsInfoByInterval
(
0
,
0
,
20000000000000
,
(
err
,
res
)
=>
{
if
(
err
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
}
else
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback success.
'
);
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback number :
'
+
(
i
+
1
));
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback result
'
+
JSON
.
stringify
(
res
[
i
]));
}
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback success.
'
);
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback number :
'
+
(
i
+
1
));
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback result
'
+
JSON
.
stringify
(
res
[
i
]));
}
}
});
}
catch
(
error
)
{
...
...
@@ -417,8 +416,8 @@ queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: num
usageStatistics
.
queryBundleStatsInfoByInterval
(
0
,
0
,
20000000000000
).
then
(
res
=>
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise success.
'
);
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise number :
'
+
(
i
+
1
));
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise result
'
+
JSON
.
stringify
(
res
[
i
]));
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise number :
'
+
(
i
+
1
));
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise result
'
+
JSON
.
stringify
(
res
[
i
]));
}
}).
catch
(
err
=>
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
...
...
@@ -467,13 +466,13 @@ queryBundleEvents(begin: number, end: number, callback: AsyncCallback<Array&l
try
{
usageStatistics
.
queryBundleEvents
(
0
,
20000000000000
,
(
err
,
res
)
=>
{
if
(
err
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleEvents callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
console
.
log
(
'
BUNDLE_ACTIVE queryBundleEvents callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
}
else
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleEvents callback success.
'
);
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleEvents callback number :
'
+
(
i
+
1
));
console
.
log
(
'
BUNDLE_ACTIVE queryBundleEvents callback result
'
+
JSON
.
stringify
(
res
[
i
]));
}
console
.
log
(
'
BUNDLE_ACTIVE queryBundleEvents callback success.
'
);
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleEvents callback number :
'
+
(
i
+
1
));
console
.
log
(
'
BUNDLE_ACTIVE queryBundleEvents callback result
'
+
JSON
.
stringify
(
res
[
i
]));
}
}
});
}
catch
(
error
)
{
...
...
@@ -526,8 +525,8 @@ queryBundleEvents(begin: number, end: number): Promise<Array<BundleEvents&
usageStatistics
.
queryBundleEvents
(
0
,
20000000000000
).
then
(
res
=>
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleEvents promise success.
'
);
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleEvents promise number :
'
+
(
i
+
1
));
console
.
log
(
'
BUNDLE_ACTIVE queryBundleEvents promise result
'
+
JSON
.
stringify
(
res
[
i
]));
console
.
log
(
'
BUNDLE_ACTIVE queryBundleEvents promise number :
'
+
(
i
+
1
));
console
.
log
(
'
BUNDLE_ACTIVE queryBundleEvents promise result
'
+
JSON
.
stringify
(
res
[
i
]));
}
}).
catch
(
err
=>
{
console
.
log
(
'
BUNDLE_ACTIVE queryBundleEvents promise failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
...
...
@@ -572,13 +571,13 @@ queryCurrentBundleEvents(begin: number, end: number, callback: AsyncCallback<
try
{
usageStatistics
.
queryCurrentBundleEvents
(
0
,
20000000000000
,
(
err
,
res
)
=>
{
if
(
err
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryCurrentBundleEvents callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
console
.
log
(
'
BUNDLE_ACTIVE queryCurrentBundleEvents callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
}
else
{
console
.
log
(
'
BUNDLE_ACTIVE queryCurrentBundleEvents callback success.
'
);
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryCurrentBundleEvents callback number :
'
+
(
i
+
1
));
console
.
log
(
'
BUNDLE_ACTIVE queryCurrentBundleEvents callback result
'
+
JSON
.
stringify
(
res
[
i
]));
}
console
.
log
(
'
BUNDLE_ACTIVE queryCurrentBundleEvents callback success.
'
);
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryCurrentBundleEvents callback number :
'
+
(
i
+
1
));
console
.
log
(
'
BUNDLE_ACTIVE queryCurrentBundleEvents callback result
'
+
JSON
.
stringify
(
res
[
i
]));
}
}
});
}
catch
(
error
)
{
...
...
@@ -627,8 +626,8 @@ queryCurrentBundleEvents(begin: number, end: number): Promise<Array<Bundle
usageStatistics
.
queryCurrentBundleEvents
(
0
,
20000000000000
).
then
(
res
=>
{
console
.
log
(
'
BUNDLE_ACTIVE queryCurrentBundleEvents promise success.
'
);
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryCurrentBundleEvents promise number :
'
+
(
i
+
1
));
console
.
log
(
'
BUNDLE_ACTIVE queryCurrentBundleEvents promise result
'
+
JSON
.
stringify
(
res
[
i
]));
console
.
log
(
'
BUNDLE_ACTIVE queryCurrentBundleEvents promise number :
'
+
(
i
+
1
));
console
.
log
(
'
BUNDLE_ACTIVE queryCurrentBundleEvents promise result
'
+
JSON
.
stringify
(
res
[
i
]));
}
}).
catch
(
err
=>
{
console
.
log
(
'
BUNDLE_ACTIVE queryCurrentBundleEvents promise failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
...
...
@@ -831,15 +830,15 @@ queryModuleUsageRecords(maxNum: number, callback: AsyncCallback<Array<HapM
```
js
try
{
usageStatistics
.
queryModuleUsageRecords
(
1000
,
(
err
,
res
)
=>
{
if
(
err
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
}
else
{
console
.
log
(
'
BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.
'
);
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryModuleUsageRecords callback number :
'
+
(
i
+
1
));
console
.
log
(
'
BUNDLE_ACTIVE queryModuleUsageRecords callback result
'
+
JSON
.
stringify
(
res
[
i
]));
if
(
err
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
}
else
{
console
.
log
(
'
BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.
'
);
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryModuleUsageRecords callback number :
'
+
(
i
+
1
));
console
.
log
(
'
BUNDLE_ACTIVE queryModuleUsageRecords callback result
'
+
JSON
.
stringify
(
res
[
i
]));
}
}
}
});
}
catch
(
error
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryModuleUsageRecords throw error, code is:
'
+
error
.
code
+
'
,message is:
'
+
error
.
message
);
...
...
@@ -893,7 +892,7 @@ queryAppGroup(bundleName : string): Promise<number>
usageStatistics
.
queryAppGroup
(
bundleName
).
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
);
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
);
...
...
@@ -939,11 +938,11 @@ queryAppGroup(bundleName : string, callback: AsyncCallback<number>): void
let
bundleName
=
"
com.ohos.camera
"
;
try
{
usageStatistics
.
queryAppGroup
(
bundleName
,
(
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
));
}
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
);
...
...
@@ -999,7 +998,7 @@ setAppGroup(bundleName: string, newGroup: GroupType): Promise<void>
usageStatistics
.
setAppGroup
(
bundleName
,
newGroup
).
then
(
()
=>
{
console
.
log
(
'
BUNDLE_ACTIVE setAppGroup promise succeeded.
'
);
}).
catch
(
err
=>
{
console
.
log
(
'
BUNDLE_ACTIVE setAppGroup promise failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
console
.
log
(
'
BUNDLE_ACTIVE setAppGroup promise failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
});
}
catch
(
error
)
{
console
.
log
(
'
BUNDLE_ACTIVE setAppGroup throw error, code is:
'
+
error
.
code
+
'
,message is:
'
+
error
.
message
);
...
...
@@ -1048,9 +1047,9 @@ setAppGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback<
try
{
usageStatistics
.
setAppGroup
(
bundleName
,
newGroup
,
(
err
)
=>
{
if
(
err
)
{
console
.
log
(
'
BUNDLE_ACTIVE setAppGroup callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
console
.
log
(
'
BUNDLE_ACTIVE setAppGroup callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
}
else
{
console
.
log
(
'
BUNDLE_ACTIVE setAppGroup callback succeeded.
'
);
console
.
log
(
'
BUNDLE_ACTIVE setAppGroup callback succeeded.
'
);
}
});
}
catch
(
error
)
{
...
...
@@ -1109,7 +1108,7 @@ registerAppGroupCallBack(groupCallback: Callback<AppGroupCallbackInfo>): P
usageStatistics
.
registerAppGroupCallBack
(
onBundleGroupChanged
).
then
(
()
=>
{
console
.
log
(
'
BUNDLE_ACTIVE registerAppGroupCallBack promise succeeded.
'
);
}).
catch
(
err
=>
{
console
.
log
(
'
BUNDLE_ACTIVE registerAppGroupCallBack promise failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
console
.
log
(
'
BUNDLE_ACTIVE registerAppGroupCallBack promise failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
});
}
catch
(
error
)
{
console
.
log
(
'
BUNDLE_ACTIVE registerAppGroupCallBack throw error, code is:
'
+
error
.
code
+
'
,message is:
'
+
error
.
message
);
...
...
@@ -1160,12 +1159,12 @@ registerAppGroupCallBack(groupCallback: Callback<AppGroupCallbackInfo>, ca
console
.
log
(
'
BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is :
'
+
res
.
bundleName
);
};
try
{
usageStatistics
.
registerAppGroupCallBack
(
onBundleGroupChanged
,
err
or
=>
{
if
(
erro
r
)
{
console
.
log
(
'
BUNDLE_ACTIVE registerAppGroupCallBack callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
}
else
{
console
.
log
(
'
BUNDLE_ACTIVE registerAppGroupCallBack callback success.
'
);
}
usageStatistics
.
registerAppGroupCallBack
(
onBundleGroupChanged
,
err
=>
{
if
(
er
r
)
{
console
.
log
(
'
BUNDLE_ACTIVE registerAppGroupCallBack callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
}
else
{
console
.
log
(
'
BUNDLE_ACTIVE registerAppGroupCallBack callback success.
'
);
}
});
}
catch
(
error
)
{
console
.
log
(
'
BUNDLE_ACTIVE registerAppGroupCallBack throw error, code is:
'
+
error
.
code
+
'
,message is:
'
+
error
.
message
);
...
...
@@ -1252,12 +1251,12 @@ unregisterAppGroupCallBack(callback: AsyncCallback<void>): void;
```
javascript
try
{
usageStatistics
.
unregisterAppGroupCallBack
(
err
or
=>
{
if
(
erro
r
)
{
console
.
log
(
'
BUNDLE_ACTIVE unregisterAppGroupCallBack callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
}
else
{
console
.
log
(
'
BUNDLE_ACTIVE unregisterAppGroupCallBack callback success.
'
);
}
usageStatistics
.
unregisterAppGroupCallBack
(
err
=>
{
if
(
er
r
)
{
console
.
log
(
'
BUNDLE_ACTIVE unregisterAppGroupCallBack callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
}
else
{
console
.
log
(
'
BUNDLE_ACTIVE unregisterAppGroupCallBack callback success.
'
);
}
});
}
catch
(
error
)
{
console
.
log
(
'
BUNDLE_ACTIVE unregisterAppGroupCallBack throw error, code is:
'
+
error
.
code
+
'
,message is:
'
+
error
.
message
);
...
...
@@ -1356,10 +1355,10 @@ queryDeviceEventStats(begin: number, end: number, callback: AsyncCallback<Arr
try
{
usageStatistics
.
queryDeviceEventStats
(
0
,
20000000000000
,
(
err
,
res
)
=>
{
if
(
err
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryDeviceEventStats callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
console
.
log
(
'
BUNDLE_ACTIVE queryDeviceEventStats callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
}
else
{
console
.
log
(
'
BUNDLE_ACTIVE queryDeviceEventStats callback success.
'
);
console
.
log
(
'
BUNDLE_ACTIVE queryDeviceEventStats callback result
'
+
JSON
.
stringify
(
res
));
console
.
log
(
'
BUNDLE_ACTIVE queryDeviceEventStats callback success.
'
);
console
.
log
(
'
BUNDLE_ACTIVE queryDeviceEventStats callback result
'
+
JSON
.
stringify
(
res
));
}
});
}
catch
(
error
)
{
...
...
@@ -1459,10 +1458,10 @@ queryNotificationEventStats(begin: number, end: number, callback: AsyncCallback&
try
{
usageStatistics
.
queryNotificationEventStats
(
0
,
20000000000000
,
(
err
,
res
)
=>
{
if
(
err
)
{
console
.
log
(
'
BUNDLE_ACTIVE queryNotificationEventStats callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
console
.
log
(
'
BUNDLE_ACTIVE queryNotificationEventStats callback failed. code is:
'
+
err
.
code
+
'
,message is:
'
+
err
.
message
);
}
else
{
console
.
log
(
'
BUNDLE_ACTIVE queryNotificationEventStats callback success.
'
);
console
.
log
(
'
BUNDLE_ACTIVE queryNotificationEventStats callback result
'
+
JSON
.
stringify
(
res
));
console
.
log
(
'
BUNDLE_ACTIVE queryNotificationEventStats callback success.
'
);
console
.
log
(
'
BUNDLE_ACTIVE queryNotificationEventStats callback result
'
+
JSON
.
stringify
(
res
));
}
});
}
catch
(
error
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录