diff --git a/zh-cn/application-dev/device-usage-statistics/device-usage-statistics-dev-guide.md b/zh-cn/application-dev/device-usage-statistics/device-usage-statistics-dev-guide.md index 37adf61598333f107d3dd7e4c204f734bbfd33df..840756a2e5e8ae9ebb27b593599584d5b07f507b 100644 --- a/zh-cn/application-dev/device-usage-statistics/device-usage-statistics-dev-guide.md +++ b/zh-cn/application-dev/device-usage-statistics/device-usage-statistics-dev-guide.md @@ -207,7 +207,7 @@ import stats from '@ohos.bundleState'; }); ``` -8. 查询FA使用记录。返回数量最大不超过maxNum设置的值,config.json中需要配置权限:ohos.permission.BUNDLE_ACTIVE_INFO。 +8. 查询FA使用记录。返回数量最大不超过maxNum设置的值,若不传入maxNum参数,则默认maxNum为1000。config.json中需要配置权限:ohos.permission.BUNDLE_ACTIVE_INFO。 ```js import stats from '@ohos.bundleState' @@ -223,6 +223,17 @@ import stats from '@ohos.bundleState'; console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise failed, because: ' + err.code); }); + // 无参数异步方法promise方式 + stats.getRecentlyUsedModules().then( res => { + console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise succeeded'); + for (let i = 0; i < res.length; i++) { + console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise number : ' + (i + 1)); + console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise result ' + JSON.stringify(res[i])); + } + }).catch( err=> { + console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise failed, because: ' + err.code); + }); + // 异步方法callback方式 stats.getRecentlyUsedModules(this.maxNum,(err, res) => { if(err) { @@ -235,5 +246,18 @@ import stats from '@ohos.bundleState'; } } }); + + // 无参数异步方法callback方式 + stats.getRecentlyUsedModules((err, res) => { + if(err) { + console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback failed, because: ' + err.code); + } else { + console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback succeeded.'); + for (let i = 0; i < res.length; i++) { + console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback number : ' + (i + 1)); + console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback result ' + JSON.stringify(res[i])); + } + } + }); ``` diff --git a/zh-cn/application-dev/device-usage-statistics/device-usage-statistics-overview.md b/zh-cn/application-dev/device-usage-statistics/device-usage-statistics-overview.md index 8ddf9ad47570326a49291ad5410d1edfd4c478ff..607dbcd18aaa0bdb88dcb2bd9102692a86412ee1 100644 --- a/zh-cn/application-dev/device-usage-statistics/device-usage-statistics-overview.md +++ b/zh-cn/application-dev/device-usage-statistics/device-usage-statistics-overview.md @@ -18,7 +18,7 @@ 4. 根据interval(日、周、月、年)类型和起止时间查询应用的使用时长。 5. 查询调用者应用的优先级群组。 6. 判断指定应用当前是否是空闲状态。 -7. 查询FA使用记录。返回数量最大不超过maxNum设置的值,FA使用记录由近及远排序,maxNum最大为1000。 +7. 查询FA使用记录。返回数量最大不超过maxNum设置的值,FA使用记录由近及远排序,maxNum最大为1000,若不填写maxNum参数,则maxNum默认为1000。 ### 设备使用信息统计使用权限 - 设备使用信息统计的queryBundleActiveStates、queryBundleStateInfos、queryBundleStateInfoByInterval接口为系统api,调用前需要申请ohos.permission.BUNDLE_ACTIVE_INFO权限。 diff --git a/zh-cn/application-dev/reference/apis/js-apis-deviceUsageStatistics.md b/zh-cn/application-dev/reference/apis/js-apis-deviceUsageStatistics.md index d29ae3281523a96b88c809d39052c1d0b1ea19c8..f7b589c23e48acea83570d69947baa17c41c7e10 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-deviceUsageStatistics.md +++ b/zh-cn/application-dev/reference/apis/js-apis-deviceUsageStatistics.md @@ -417,7 +417,7 @@ getRecentlyUsedModules(maxNum: number): Promise<Array<BundleActiveModuleIn | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | - | maxNum | number | 是 | 返回条目的最大数量。| + | maxNum | number | 否 | 返回条目的最大数量,若不填写,则默认为1000。| **返回值**: @@ -437,6 +437,17 @@ getRecentlyUsedModules(maxNum: number): Promise<Array<BundleActiveModuleIn }).catch( err=> { console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise failed, because: ' + err.code); }); + + // 无参数调用方式 + bundleState.getRecentlyUsedModules().then( res => { + console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise succeeded'); + for (let i = 0; i < res.length; i++) { + console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise number : ' + (i + 1)); + console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise result ' + JSON.stringify(res[i])); + } + }).catch( err=> { + console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise failed, because: ' + err.code); + }); ``` ## bundleState.getRecentlyUsedModules9+ @@ -453,7 +464,7 @@ getRecentlyUsedModules(maxNum: number, callback: AsyncCallback<Array<Bundl | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | - | maxNum | number | 是 | 返回条目的最大数量。| + | maxNum | number | 否 | 返回条目的最大数量,若不填写,则默认为1000。| | callback | AsyncCallback<Array<[BundleActiveModuleInfo](#bundleactivestate)>> | 是 | 指定的CallBack回调方法。返回不超过maxNum条FA使用记录。| **示例**: @@ -470,13 +481,24 @@ getRecentlyUsedModules(maxNum: number, callback: AsyncCallback<Array<Bundl } } }); + + // 无参数调用方式 + stats.getRecentlyUsedModules((err, res) => { + if(err) { + console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback failed, because: ' + err.code); + } else { + console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback succeeded.'); + for (let i = 0; i < res.length; i++) { + console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback number : ' + (i + 1)); + console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback result ' + JSON.stringify(res[i])); + } + } + }); ``` ## BundleActiveModuleInfo9+ FA的使用信息的属性集合。 -### 属性 - **系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App | 参数名 | 类型 | 必填 | 说明 | @@ -487,7 +509,7 @@ FA的使用信息的属性集合。 | abilityName | string | 是 | FA的MainAbility名。| | appLabelId | number | 是 | FA的应用labelId。| | labelId | number | 是 | FA所属module的labelId。| -| descriptionId | number | 是 | FA的应用descriptionId。| +| descriptionId | number | 是 | FA所属的应用descriptionId。| | abilityLableId | number | 是 | FA的MainAbility labelId。| | abilityDescriptionId | number | 是 | FA的MainAbility descriptionId。| | abilityIconId | number | 是 | FA的MainAbility iconId。| @@ -498,8 +520,6 @@ FA的使用信息的属性集合。 ## BundleActiveFormInfo9+ FA卡片的使用信息的属性集合。 -### 属性 - **系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App | 参数名 | 类型 | 必填 | 说明 |