Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
6ce7f373
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
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看板
未验证
提交
6ce7f373
编写于
3月 09, 2022
作者:
O
openharmony_ci
提交者:
Gitee
3月 09, 2022
浏览文件
操作
浏览文件
下载
差异文件
!1906 modify file
Merge pull request !1906 from wangyuanchao/master
上级
51307b5b
67dd61b9
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
210 addition
and
191 deletion
+210
-191
zh-cn/application-dev/device-usage-statistics/device-usage-statistics-dev-guide.md
...ice-usage-statistics/device-usage-statistics-dev-guide.md
+92
-110
zh-cn/application-dev/device-usage-statistics/device-usage-statistics-overview.md
...vice-usage-statistics/device-usage-statistics-overview.md
+2
-2
zh-cn/application-dev/reference/apis/js-apis-deviceUsageStatistics.md
...ation-dev/reference/apis/js-apis-deviceUsageStatistics.md
+116
-79
未找到文件。
zh-cn/application-dev/device-usage-statistics/device-usage-statistics-dev-guide.md
浏览文件 @
6ce7f373
...
...
@@ -8,7 +8,7 @@
## 接口说明
注册相关接口包导入:
```
js
import
stats
from
'
@ohos.
usagestatskit
'
;
import
stats
from
'
@ohos.
bundleState
'
;
```
**表1**
设备使用信息统计主要接口
...
...
@@ -38,188 +38,170 @@ import stats from '@ohos.usagestatskit';
}
```
2.
通过指定起始和结束时间查询所有应用的事件集合。
2.
通过指定起始和结束时间查询所有应用的事件集合
,config.json中需要配置权限:ohos.permission.BUNDLE_ACTIVE_INFO
。
```js
import stats from '@ohos.
usagestatskit
'
import stats from '@ohos.
bundleState
'
// 异步方法promise方式
stats.queryBundleActiveStates(0, 20000000000000).then( res => {
console.log('
queryBundleActiveStates promise succeeded, data number: ' + res.length
);
console.log('
BUNDLE_ACTIVE queryBundleActiveStates promise success.'
);
for (let i = 0; i < res.length; i++) {
console.log("queryBundleActiveStates, promise bundleName = " + res[i].bundleName)
console.log("queryBundleActiveStates, promise stateType = " + res[i].stateType)
console.log("queryBundleActiveStates, promise stateOccurredTime = " + res[i].stateOccurredTime)
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i]));
}
}).catch( err => {
console.log('
queryBundleActiveStates promise failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code
);
});
// 异步方法callback方式
setTimeout(()=>{
stats.queryBundleActiveStates(0, 20000000000000, (err, res) => {
console.log('queryBundleActiveStates callback succeeded, data number: ' + res.length);
if(err.data == 0) {
if(err.code == 0) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback success.');
for (let i = 0; i < res.length; i++) {
console.log("queryBundleActiveStates, callback bundleName = " + res[i].bundleName)
console.log("queryBundleActiveStates, callback stateType = " + res[i].stateType)
console.log("queryBundleActiveStates, callback stateOccurredTime = " + res[i].stateOccurredTime)
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback result ' + JSON.stringify(res[i]));
}
} else {
console.log('queryBundleActiveStates callback failed, because: ' + err.data
);
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback failed, because: ' + err.code
);
}
})
}, 500);
});
```
3.
通过指定起始和结束时间查询应用使用时长统计信息。
3.
通过指定起始和结束时间查询应用使用时长统计信息
,config.json中需要配置权限:ohos.permission.BUNDLE_ACTIVE_INFO
。
```js
import stats from '@ohos.
usagestatskit
'
import stats from '@ohos.
bundleState
'
// 异步方法promise方式
stats.queryBundleStateInfos(0, 20000000000000).then( res => {
console.log('queryBundleStateInfos promise succeeded, data number: ' + res.length);
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.');
let i = 1;
for(let key in res){
console.log("queryBundleStateInfos promise key = " + key)
console.log("queryBundleStateInfos promise bundleName = " + res[key].bundleName)
console.log("queryBundleStateInfos promise abilityPrevAccessTime = " + res[key].abilityPrevAccessTime)
console.log("queryBundleStateInfos promise abilityInFgTotalTime = " + res[key].abilityInFgTotalTime)
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key]));
i++;
}
}).catch( err => {
console.log('
queryBundleStateInfos promise failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code
);
});
// 异步方法callback方式
s
etTimeout(()=>
{
stats.queryBundleStateInfos(0, 20000000000000,(err, res) =>
{
console.log('
queryBundleStateInfos callback succeeded, data number: ' + res.length
);
if(err.data == 0) {
s
tats.queryBundleStateInfos(0, 20000000000000, (err, res) =>
{
if(err.code == 0)
{
console.log('
BUNDLE_ACTIVE queryBundleStateInfos callback success.'
);
let i = 1;
for(let key in res){
console.log("queryBundleStateInfos callback key = " + key)
console.log("queryBundleStateInfos callback bundleName = " + res[key].bundleName)
console.log("queryBundleStateInfos callback abilityPrevAccessTime = " + res[key].abilityPrevAccessTime)
console.log("queryBundleStateInfos callback abilityInFgTotalTime = " + res[key].abilityInFgTotalTime)
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback result ' + JSON.stringify(res[key]));
i++;
}
} else {
console.log('queryBundleStateInfos callback failed, because: ' + err.data
);
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback failed, because: ' + err.code
);
}
})
}, 500);
});
```
4.
通过指定起始和结束时间查询当前应用的事件集合。
4.
通过指定起始和结束时间查询当前应用的事件集合
,config.json中不需要配置权限
。
```js
import stats from '@ohos.
usagestatskit
'
import stats from '@ohos.
bundleState
'
// 异步方法promise方式
stats.queryCurrentBundleActiveStates(0, 20000000000000).then( res => {
console.log('
queryCurrentBundleActiveStates promise succeeded, data number: ' + res.length
);
console.log('
BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.'
);
for (let i = 0; i < res.length; i++) {
console.log("queryCurrentBundleActiveStates, promise bundleName = " + res[i].bundleName)
console.log("queryCurrentBundleActiveStates, promise stateType = " + res[i].stateType)
console.log("queryCurrentBundleActiveStates, promise stateOccurredTime = " + res[i].stateOccurredTime)
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i]));
}
}).catch( err => {
console.log('
queryCurrentBundleActiveStates promise failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code
);
});
// 异步方法callback方式
setTimeout(()=>{
stats.queryCurrentBundleActiveStates(0, 20000000000000,(err, res) => {
console.log('queryCurrentBundleActiveStates callback succeeded, data number: ' + res.length);
if(err.data == 0) {
stats.queryCurrentBundleActiveStates(0, 20000000000000, (err, res) => {
if(err.code == 0) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback success.');
for (let i = 0; i < res.length; i++) {
console.log("queryCurrentBundleActiveStates, callback bundleName = " + res[i].bundleName)
console.log("queryCurrentBundleActiveStates, callback stateType = " + res[i].stateType)
console.log("queryCurrentBundleActiveStates, callback stateOccurredTime = " + res[i].stateOccurredTime)
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback result ' + JSON.stringify(res[i]));
}
} else {
console.log('queryCurrentBundleActiveStates callback failed, because: ' + err.data
);
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failed, because: ' + err.code
);
}
})
}, 500);
});
```
5.
通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息。
5.
通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息
,config.json中需要配置权限:ohos.permission.BUNDLE_ACTIVE_INFO
。
```js
import stats from '@ohos.
usagestatskit
'
import stats from '@ohos.
bundleState
'
// 异步方法promise方式
stats.queryBundleStateInfoByInterval(0, 0, 20000000000000).then( res => {
console.log('
queryBundleStateInfoByInterval promise succeeded, data number: ' + res.length
);
console.log('
BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.'
);
for (let i = 0; i < res.length; i++) {
console.log("queryBundleStateInfoByInterval, promise bundleName = " + res[i].bundleName)
console.log("queryBundleStateInfoByInterval, promise abilityPrevAccessTime = " + res[i].abilityPrevAccessTime)
console.log("queryBundleStateInfoByInterval, promise abilityInFgTotalTime = " + res[i].abilityInFgTotalTime)
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i]));
}
}).catch( err => {
console.log('
queryBundleStateInfoByiInterval promise failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code
);
});
// 异步方法callback方式
setTimeout(()=>{
stats.queryBundleStateInfoByInterval(0, 0, 20000000000000,(err, res) => {
console.log('queryBundleStateInfoByInterval callback succeeded, data number: ' + res.length);
if(err.data == 0) {
stats.queryBundleStateInfoByInterval(0, 0, 20000000000000, (err, res) => {
if(err.code == 0) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback success.');
for (let i = 0; i < res.length; i++) {
console.log("queryBundleStateInfoByInterval, callback bundleName = " + res[i].bundleName)
console.log("queryBundleStateInfoByInterval, callback abilityPrevAccessTime = " + res[i].abilityPrevAccessTime)
console.log("queryBundleStateInfoByInterval, callback abilityInFgTotalTime = " + res[i].abilityInFgTotalTime)
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback result ' + JSON.stringify(res[i]));
}
} else {
console.log('queryBundleStateInfoByInterval callback failed, because: ' + err.data
);
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failed, because: ' + err.code
);
}
})
}, 500);
});
```
6.
查询(返回)当前调用者应用的使用优先级群组。
6.
查询(返回)当前调用者应用的使用优先级群组
,config.json中不需要配置权限
。
```js
import stats from '@ohos.
usagestatskit
'
import stats from '@ohos.
bundleState
'
// 异步方法promise方式
stats.queryAppUsagePriorityGroup().then( res => {
console.log('queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res));
console.log('
BUNDLE_ACTIVE
queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch( err => {
console.log('
queryAppUsagePriorityGroup promise failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code
);
});
// 异步方法callback方式
setTimeout(()=>{
stats.queryAppUsagePriorityGroup((err, res) => {
if(err.data
=== 0) {
console.log('
queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
if(err.code
=== 0) {
console.log('BUNDLE_ACTIVE
queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
} else {
console.log('queryAppUsagePriorityGroup callback failed, because: ' + err.data
);
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback failed. because: ' + err.code
);
}
})
}, 500);
});
```
7.
判断指定Bundle Name的应用当前是否是空闲状态。
7.
判断指定Bundle Name的应用当前是否是空闲状态
,config.json中不需要配置权限
。
```js
import stats from '@ohos.
usagestatskit
'
import stats from '@ohos.
bundleState
'
// 异步方法promise方式
stats.isIdleState("com.ohos.camera").then( res => {
console.log('
isIdleState promise succeeded.
result: ' + JSON.stringify(res));
console.log('
BUNDLE_ACTIVE isIdleState promise succeeded,
result: ' + JSON.stringify(res));
}).catch( err => {
console.log('
isIdleState promise failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code
);
});
// 异步方法callback方式
setTimeout(()=>{
stats.isIdleState("com.ohos.camera", (err, res) => {
if(err.data
=== 0) {
console.log('isIdleState callback succeeded.
result: ' + JSON.stringify(res));
if(err.code
=== 0) {
console.log('BUNDLE_ACTIVE isIdleState callback succeeded,
result: ' + JSON.stringify(res));
} else {
console.log('isIdleState callback failed, because: ' + err.data
);
console.log('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code
);
}
})
}, 500);
});
```
\ No newline at end of file
zh-cn/application-dev/device-usage-statistics/device-usage-statistics-overview.md
浏览文件 @
6ce7f373
...
...
@@ -20,5 +20,5 @@
>6. 判断指定应用当前是否是空闲状态;
### 设备使用信息统计使用权限
-
设备使用信息统计接口只对系统应用开放,三方应用不可调用。
-
系统应用调用设备使用信息统计接口前,必须申请ohos.permission.BUNDLE_ACTIVE_INFO权限。
\ No newline at end of file
-
设备使用信息统计的queryBundleActiveStates、queryBundleStateInfos、queryBundleStateInfoByInterval接口为系统api,调用前需要申请ohos.permission.BUNDLE_ACTIVE_INFO权限。
-
设备使用信息统计的queryCurrentBundleActiveStates、queryAppUsagePriorityGroup、isIdleState接口为三方api,调用时不需要申请权限。
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-deviceUsageStatistics.md
浏览文件 @
6ce7f373
...
...
@@ -7,10 +7,10 @@
## 导入模块
```
import stats from '@ohos.
usagestatskit
'
import stats from '@ohos.
bundleState
'
```
##
usagestatskit
.isIdleState
##
bundleState
.isIdleState
isIdleState(bundleName: string, callback: AsyncCallback
<boolean>
): void
-
**系统能力**
:
...
...
@@ -26,20 +26,22 @@ SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
| bundleName | string | 是 | 应用的bundleName。|
| callback | AsyncCallback
<boolean>
| 是 | 指定的callback回调方法。如果指定的bundleName有效,则返回指定bundleName的应用当前是否是空闲状态;否则返回null。 |
-
**权限**
:
无权限
-
**示例**
:
```
stats.isIdleState("com.ohos.camera", (err, res) => {
if(err.
data
=== 0) {
console.log('isIdleState callback succeeded, result: ' + JSON.stringify(res));
if(err.
code
=== 0) {
console.log('
BUNDLE_ACTIVE
isIdleState callback succeeded, result: ' + JSON.stringify(res));
} else {
console.log('
isIdleState callback failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code
);
}
});
```
##
usagestatskit
.isIdleState
##
bundleState
.isIdleState
isIdleState(bundleName: string): Promise
<boolean>
;
-
**系统能力**
:
...
...
@@ -60,17 +62,20 @@ SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
| -------- | -------- |
| Promise
<boolean>
| 指定的Promise回调方法。如果指定的bundleName有效,则返回指定bundleName的应用当前是否是空闲状态;否则返回null。 |
-
**权限**
:
无权限
-
**示例**
:
```
stats.isIdleState("com.ohos.camera").then( res => {
console.log('
isIdleState callback
succeeded, result: ' + JSON.stringify(res));
console.log('
BUNDLE_ACTIVE isIdleState promise
succeeded, result: ' + JSON.stringify(res));
}).catch( err => {
console.log('
isIdleState callback failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code
);
});
```
##
usagestatskit
.queryAppUsagePriorityGroup
##
bundleState
.queryAppUsagePriorityGroup
queryAppUsagePriorityGroup(callback: AsyncCallback
<number>
): void
-
**系统能力**
:
...
...
@@ -85,19 +90,22 @@ SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<number>
| 是 | 指定的callback回调方法。返回当前调用者应用的使用优先级群组。|
-
**权限**
:
无权限
-
**示例**
:
```
stats.queryAppUsagePriorityGroup((err, res) => {
if(err.
data
=== 0) {
console.log('queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
if(err.
code
=== 0) {
console.log('
BUNDLE_ACTIVE
queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
} else {
console.log('
queryAppUsagePriorityGroup callback failed. because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryAppUsagePriorityGroup callback failed. because: ' + err.code
);
}
});
```
##
usagestatskit
.queryAppUsagePriorityGroup
##
bundleState
.queryAppUsagePriorityGroup
queryAppUsagePriorityGroup(): Promise
<number>
-
**系统能力**
:
...
...
@@ -112,17 +120,20 @@ SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
| -------- | -------- |
| Promise
<number>
| 指定的Promise回调方法。查询(返回)当前调用者应用的使用优先级群组。|
-
**权限**
:
无权限
-
**示例**
:
```
stats.queryAppUsagePriorityGroup().then( res => {
console.log('queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res));
console.log('
BUNDLE_ACTIVE
queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch( err => {
console.log('
queryAppUsagePriorityGroup promise failed. because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code
);
});
```
##
usagestatskit
.queryBundleStateInfos
##
bundleState
.queryBundleStateInfos
queryBundleStateInfos(begin: number, end: number, callback: AsyncCallback
<BundleActiveInfoResponse>
): void
-
**系统能力**
:
...
...
@@ -139,25 +150,28 @@ SystemCapability.ResourceSchedule.UsageStatistics.App
| end | number | 是 | 结束时间。|
| callback | AsyncCallback
<BundleActiveInfoResponse>
| 是 | 指定的callback回调方法。返回指定起始和结束时间内应用使用时长统计信息。|
-
**权限**
:
ohos.permission.BUNDLE_ACTIVE_INFO
-
**示例**
:
```
stats.queryBundleStateInfos(0, 20000000000000, (err, res) => {
console.log('queryBundleStateInfos callback succeeded, data number: ' + res.length);
if(err.data == 0) {
if(err.code == 0) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback success.');
let i = 1;
for(let key in res){
console.log("queryBundleStateInfos callback key = " + key)
console.log("queryBundleStateInfos callback bundleName = " + res[key].bundleName)
console.log("queryBundleStateInfos callback abilityPrevAccessTime = " + res[key].abilityPrevAccessTime)
console.log("queryBundleStateInfos callback abilityInFgTotalTime = " + res[key].abilityInFgTotalTime)
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback result ' + JSON.stringify(res[key]));
i++;
}
} else {
console.log('
queryBundleStateInfos callback failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryBundleStateInfos callback failed, because: ' + err.code
);
}
});
```
##
usagestatskit
.queryBundleStateInfos
##
bundleState
.queryBundleStateInfos
queryBundleStateInfos(begin: number, end: number): Promise
<BundleActiveInfoResponse>
-
**系统能力**
:
...
...
@@ -179,23 +193,26 @@ SystemCapability.ResourceSchedule.UsageStatistics.App
| -------- | -------- |
| Promise
<BundleActiveInfoResponse>
| 指定的Promise回调方法。返回指定起始和结束时间内应用使用时长统计信息。|
-
**权限**
:
ohos.permission.BUNDLE_ACTIVE_INFO
-
**示例**
:
```
stats.queryBundleStateInfos(0, 20000000000000).then( res => {
console.log('queryBundleStateInfos promise succeeded, data number: ' + res.length);
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.');
let i = 1;
for(let key in res){
console.log("queryBundleStateInfos promise key = " + key)
console.log("queryBundleStateInfos promise bundleName = " + res[key].bundleName)
console.log("queryBundleStateInfos promise abilityPrevAccessTime = " + res[key].abilityPrevAccessTime)
console.log("queryBundleStateInfos promise abilityInFgTotalTime = " + res[key].abilityInFgTotalTime)
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key]));
i++;
}
}).catch( err => {
console.log('
queryBundleStateInfos promise failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code
);
});
```
##
usagestatskit
.queryBundleStateInfoByInterval
##
bundleState
.queryBundleStateInfoByInterval
queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback
<Array
<
BundleStateInfo
>
>): void
-
**系统能力**
:
...
...
@@ -213,24 +230,26 @@ SystemCapability.ResourceSchedule.UsageStatistics.App
| end | number | 是 | 结束时间。|
| callback | AsyncCallback
<Array
<
BundleStateInfo
>
> | 是 | 指定的callback回调方法。返回指定时间段间隔(天、周、月、年)查询应用使用时长统计信息。|
-
**权限**
:
ohos.permission.BUNDLE_ACTIVE_INFO
-
**示例**
:
```
stats.queryBundleStateInfoByInterval(0, 0, 20000000000000, (err, res) => {
console.log('queryBundleStateInfoByInterval callback succeeded, data number: ' + res.length);
if(err.data == 0) {
if(err.code == 0) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback success.');
for (let i = 0; i < res.length; i++) {
console.log("queryBundleStateInfoByInterval, callback bundleName = " + res[i].bundleName)
console.log("queryBundleStateInfoByInterval, callback abilityPrevAccessTime = " + res[i].abilityPrevAccessTime)
console.log("queryBundleStateInfoByInterval, callback abilityInFgTotalTime = " + res[i].abilityInFgTotalTime)
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback result ' + JSON.stringify(res[i]));
}
} else {
console.log('
queryBundleStateInfoByInterval callback failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failed, because: ' + err.code
);
}
});
```
##
usagestatskit
.queryBundleStateInfoByInterval
##
bundleState
.queryBundleStateInfoByInterval
queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number): Promise
<Array
<
BundleStateInfo
>
>
-
**系统能力**
:
...
...
@@ -253,22 +272,24 @@ SystemCapability.ResourceSchedule.UsageStatistics.App
| -------- | -------- |
| Promise
<Array
<
BundleStateInfo
>
> | 指定的Promise回调方法。返回指定时间段间隔(天、周、月、年)查询应用使用时长统计信息。|
-
**权限**
:
ohos.permission.BUNDLE_ACTIVE_INFO
-
**示例**
:
```
stats.queryBundleStateInfoByInterval(0, 0, 20000000000000).then( res => {
console.log('
queryBundleStateInfoByInterval promise succeeded, data number: ' + res.length
);
console.log('
BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.'
);
for (let i = 0; i < res.length; i++) {
console.log("queryBundleStateInfoByInterval, promise bundleName = " + res[i].bundleName)
console.log("queryBundleStateInfoByInterval, promise abilityPrevAccessTime = " + res[i].abilityPrevAccessTime)
console.log("queryBundleStateInfoByInterval, promise abilityInFgTotalTime = " + res[i].abilityInFgTotalTime)
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i]));
}
}).catch( err => {
console.log('
queryBundleStateInfoByiInterval promise failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code
);
});
```
##
usagestatskit
.queryBundleActiveStates
##
bundleState
.queryBundleActiveStates
queryBundleActiveStates(begin: number, end: number, callback: AsyncCallback
<Array
<
BundleActiveState
>
>): void
-
**系统能力**
:
...
...
@@ -285,24 +306,26 @@ SystemCapability.ResourceSchedule.UsageStatistics.App
| end | number | 是 | 结束时间。|
| callback | AsyncCallback
<Array
<
BundleActiveState
>
> | 是 | 指定的callback回调方法。返回指定起始和结束时间查询所有应用的事件集合。|
-
**权限**
:
ohos.permission.BUNDLE_ACTIVE_INFO
-
**示例**
:
```
stats.queryBundleActiveStates(0, 20000000000000, (err, res) => {
console.log('queryBundleActiveStates callback succeeded, data number: ' + res.length);
if(err.data == 0) {
if(err.code == 0) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback success.');
for (let i = 0; i < res.length; i++) {
console.log("queryBundleActiveStates, callback bundleName = " + res[i].bundleName)
console.log("queryBundleActiveStates, callback stateType = " + res[i].stateType)
console.log("queryBundleActiveStates, callback stateOccurredTime = " + res[i].stateOccurredTime)
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback result ' + JSON.stringify(res[i]));
}
} else {
console.log('
queryBundleActiveStates callback failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryBundleActiveStates callback failed, because: ' + err.code
);
}
});
```
##
usagestatskit
.queryBundleActiveStates
##
bundleState
.queryBundleActiveStates
queryBundleActiveStates(begin: number, end: number): Promise
<Array
<
BundleActiveState
>
>
-
**系统能力**
:
...
...
@@ -324,22 +347,24 @@ SystemCapability.ResourceSchedule.UsageStatistics.App
| -------- | -------- |
| Promise
<Array
<
BundleActiveState
>
> | 指定的Promise回调方法。返回指定起始和结束时间查询所有应用的事件集合。|
-
**权限**
:
ohos.permission.BUNDLE_ACTIVE_INFO
-
**示例**
:
```
stats.queryBundleActiveStates(0, 20000000000000).then( res => {
console.log('
queryBundleActiveStates promise succeeded, data number: ' + res.length
);
console.log('
BUNDLE_ACTIVE queryBundleActiveStates promise success.'
);
for (let i = 0; i < res.length; i++) {
console.log("queryBundleActiveStates, promise bundleName = " + res[i].bundleName)
console.log("queryBundleActiveStates, promise stateType = " + res[i].stateType)
console.log("queryBundleActiveStates, promise stateOccurredTime = " + res[i].stateOccurredTime)
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i]));
}
}).catch( err => {
console.log('
queryBundleActiveStates promise failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code
);
});
```
##
usagestatskit
.queryCurrentBundleActiveStates
##
bundleState
.queryCurrentBundleActiveStates
queryCurrentBundleActiveStates(begin: number, end: number, callback: AsyncCallback
<Array
<
BundleActiveState
>
>): void
-
**系统能力**
:
...
...
@@ -356,24 +381,26 @@ SystemCapability.ResourceSchedule.UsageStatistics.App
| end | number | 是 | 结束时间。|
| callback | AsyncCallback
<Array
<
BundleActiveState
>
> | 是 | 指定的callback回调方法。返回指定起始和结束时间查询当前应用的事件集合。|
-
**权限**
:
无权限
-
**示例**
:
```
stats.queryCurrentBundleActiveStates(0, 20000000000000,(err, res) => {
console.log('queryCurrentBundleActiveStates callback succeeded, data number: ' + res.length);
if(err.data == 0) {
stats.queryCurrentBundleActiveStates(0, 20000000000000,
(err, res) => {
if(err.code == 0) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback success.');
for (let i = 0; i < res.length; i++) {
console.log("queryCurrentBundleActiveStates, callback bundleName = " + res[i].bundleName)
console.log("queryCurrentBundleActiveStates, callback stateType = " + res[i].stateType)
console.log("queryCurrentBundleActiveStates, callback stateOccurredTime = " + res[i].stateOccurredTime)
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback result ' + JSON.stringify(res[i]));
}
} else {
console.log('
queryCurrentBundleActiveStates callback failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failed, because: ' + err.code
);
}
});
```
##
usagestatskit
.queryCurrentBundleActiveStates
##
bundleState
.queryCurrentBundleActiveStates
queryCurrentBundleActiveStates(begin: number, end: number): Promise
<Array
<
BundleActiveState
>
>
-
**系统能力**
:
...
...
@@ -395,26 +422,30 @@ SystemCapability.ResourceSchedule.UsageStatistics.App
| -------- | -------- |
| Promise
<Array
<
BundleActiveState
>
> | 指定的Promise回调方法。返回指定起始和结束时间查询当前应用的事件集合。|
-
**权限**
:
无权限
-
**示例**
:
```
stats.queryCurrentBundleActiveStates(0, 20000000000000).then( res => {
console.log('
queryCurrentBundleActiveStates promise succeeded, data number: ' + res.length
);
console.log('
BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.'
);
for (let i = 0; i < res.length; i++) {
console.log("queryCurrentBundleActiveStates, promise bundleName = " + res[i].bundleName)
console.log("queryCurrentBundleActiveStates, promise stateType = " + res[i].stateType)
console.log("queryCurrentBundleActiveStates, promise stateOccurredTime = " + res[i].stateOccurredTime)
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i]));
}
}).catch( err => {
console.log('
queryCurrentBundleActiveStates promise failed, because: ' + err.data
);
console.log('
BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code
);
});
```
##
usagestatskit
.BundleStateInfo
##
bundleState
.BundleStateInfo
-
**系统能力**
:
SystemCapability.ResourceSchedule.UsageStatistics.App
提供应用使用时长的具体信息。
-
**参数**
:
提供应用使用时长的具体信息。
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
...
...
@@ -422,11 +453,13 @@ SystemCapability.ResourceSchedule.UsageStatistics.App
| abilityPrevAccessTime | number | 是 | 应用最后一次使用的时间。|
| abilityInFgTotalTime | number | 是 | 应用在前台使用的总时间。|
##
usagestatskit
.BundleActiveState
##
bundleState
.BundleActiveState
-
**系统能力**
:
SystemCapability.ResourceSchedule.UsageStatistics.App
提供应用事件的具体信息。
-
**参数**
:
提供应用事件的具体信息。
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
...
...
@@ -434,21 +467,25 @@ SystemCapability.ResourceSchedule.UsageStatistics.App
| stateType | number | 是 | 应用事件类型。|
| stateOccurredTime | number | 是 | 应用事件发生的时间戳。|
##
usagestatskit
.BundleActiveInfoResponse
##
bundleState
.BundleActiveInfoResponse
-
**系统能力**
:
SystemCapability.ResourceSchedule.UsageStatistics.App
提供应用使用时长的具体信息。
-
**参数**
:
提供应用使用时长的具体信息。
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| [key: string]: BundleStateInfo | BundleStateInfo | 是 | 不同应用的使用时长统计信息。|
##
usagestatskit
.IntervalType
##
bundleState
.IntervalType
-
**系统能力**
:
SystemCapability.ResourceSchedule.UsageStatistics.App
触发工作的网络类型。
-
**参数**
:
提供查询的类型
|名称 |默认值 |说明|
| -------- | -------- | -------- |
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录