@ohos.file.storageStatistics (应用空间统计)

该模块提供空间查询相关的常用功能:包括对内外卡的空间查询,对应用分类数据统计的查询,对应用数据的查询等。

说明:

本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

import storageStatistics from "@ohos.file.storageStatistics";

storageStatistics.getCurrentBundleStats9+

getCurrentBundleStats(): Promise<BundleStats>

第三方应用异步获取当前应用存储空间大小(单位为Byte),以Promise方式返回。

系统能力:SystemCapability.FileManagement.StorageService.SpatialStatistics

返回值:

类型 说明
Promise<Bundlestats> Promise对象,返回指定卷上的应用存储空间大小(单位为Byte)

错误码:

以下错误码的详细介绍请参见文件管理错误码

错误码ID 错误信息
401 The input parameter is invalid.
13600001 IPC error.
13900042 Unknown error.

示例:

import { BusinessError } from '@ohos.base';
storageStatistics.getCurrentBundleStats().then((BundleStats: storageStatistics.BundleStats) => {
  console.info("getCurrentBundleStats successfully:" + JSON.stringify(BundleStats));
}).catch((err: BusinessError) => {
  console.error("getCurrentBundleStats failed with error:"+ JSON.stringify(err));
});

storageStatistics.getCurrentBundleStats9+

getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void

第三方应用异步获取当前应用存储空间大小(单位为Byte),以callback方式返回。

系统能力:SystemCapability.FileManagement.StorageService.SpatialStatistics

参数:

参数名 类型 必填 说明
callback AsyncCallback<BundleStats> 获取指定卷上的应用存储空间大小之后的回调

错误码:

以下错误码的详细介绍请参见文件管理错误码

错误码ID 错误信息
401 The input parameter is invalid.
13600001 IPC error.
13900042 Unknown error.

示例:

import { BusinessError } from '@ohos.base';
storageStatistics.getCurrentBundleStats((error: BusinessError, bundleStats: storageStatistics.BundleStats) => {
  if (error) {
    console.error("getCurrentBundleStats failed with error:" + JSON.stringify(error));
  } else {
    // do something
    console.info("getCurrentBundleStats successfully:" + JSON.stringify(bundleStats));
  }
});

BundleStats9+

系统能力:SystemCapability.FileManagement.StorageService.SpatialStatistics

名称 类型 可读 可写 说明
appSize number app数据大小(单位为Byte)
cacheSize number 缓存数据大小(单位为Byte)
dataSize number 应用总数据大小(单位为Byte)