harmony 鸿蒙@ohos.storageStatistics (应用空间统计)

  • 2022-08-09
  • 浏览 (496)

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

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

说明:

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

导入模块

import storageStatistics from "@ohos.storageStatistics";

storageStatistics.getTotalSizeOfVolume

getTotalSizeOfVolume(volumeUuid: string): Promise<number>

异步获取指定卷的总空间大小,以promise方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

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

该接口为系统接口,三方应用不支持调用

参数:

参数名 类型 必填 说明
volumeUuid string 卷id

返回值:

类型 说明
Promise<number> 返回指定卷总空间

示例:

  let uuid = "";
  storageStatistics.getTotalSizeOfVolume(uuid).then(function(number){
      console.info("getTotalSizeOfVolume successfully:"+ number);
  }).catch(function(err){
      console.info("getTotalSizeOfVolume failed with error:"+ err);
  });

storageStatistics.getTotalSizeOfVolume

getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void

异步获取指定卷的总空间大小,以callback方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

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

该接口为系统接口,三方应用不支持调用

参数:

参数名 类型 必填 说明
volumeUuid string 卷id
callback AsyncCallback<number> 获取指定卷总空间之后的回调

示例:

  let uuid = "";
  storageStatistics.getTotalSizeOfVolume(uuid, function(error, number){
      // do something
      console.info("getTotalSizeOfVolume successfully:"+ number);
  });

storageStatistics.getFreeSizeOfVolume

getFreeSizeOfVolume(volumeUuid: string): Promise<number>

异步获取指定卷的可用空间大小,以promise方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

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

该接口为系统接口,三方应用不支持调用

参数:

参数名 类型 必填 说明
volumeUuid string 卷id

返回值:

类型 说明
Promise<number> 返回指定卷可用空间

示例:

  let uuid = "";
  storageStatistics.getFreeSizeOfVolume(uuid).then(function(number){
      console.info("getFreeSizeOfVolume successfully:"+ number);
  }).catch(function(err){
      console.info("getFreeSizeOfVolume failed with error:"+ err);
  });
  

storageStatistics.getFreeSizeOfVolume

getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void

异步获取指定卷的可用空间大小,以callback方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

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

该接口为系统接口,三方应用不支持调用

参数:

参数名 类型 必填 说明
volumeUuid string 卷id
callback AsyncCallback<number> 获取指定卷可用空间之后的回调

示例:

  let uuid = "";
  storageStatistics.getFreeSizeOfVolume(uuid, function(error, number){
      // do something
      console.info("getFreeSizeOfVolume successfully:"+ number);
  });

storageStatistics.getBundleStats9+

getBundleStats(packageName: string): Promise<BundleStats>

异步获取应用存储数据,以promise方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

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

该接口为系统接口,三方应用不支持调用

参数:

参数名 类型 必填 说明
packageName string 应用包名

返回值:

类型 说明
Promise<Bundlestats> 返回指定卷上的应用存储数据

示例:

  let packageName = "";
  storageStatistics.getBundleStats(packageName).then(function(BundleStats){
      console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
  }).catch(function(err){
      console.info("getBundleStats failed with error:"+ err);
  });

storageStatistics.getBundleStats9+

getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>): void

异步获取应用存储数据,以callback方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

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

该接口为系统接口,三方应用不支持调用

参数:

参数名 类型 必填 说明
packageName string 应用包名
callback AsyncCallback<Bundlestats> 获取指定卷上的应用存储数据之后的回调

示例:

  let packageName = "";
  storageStatistics.getBundleStats(packageName, function(error, BundleStats){
      // do something
      console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
  });

storageStatistics.getCurrentBundleStats9+

getCurrentBundleStats(): Promise<BundleStats>

第三方应用异步获取占用空间,以promise方式返回。

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

返回值:

类型 说明
Promise<Bundlestats> 返回指定卷上的应用存储状态

示例:

  let bundleStats = storageStatistics.getCurrentBundleStats();
  console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));

storageStatistics.getCurrentBundleStats9+

getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void

第三方应用异步获取占用空间,以callback方式返回。

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

参数:

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

示例:

  storageStatistics.getCurrentBundleStats(function(error, bundleStats){
      // do something
      console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
  });

BundleStats9+

属性

系统能力:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics

该接口为系统接口,三方应用不支持调用

名称 类型 可读 可写 说明
appSize number app数据大小
cacheSize number 缓存数据大小
dataSize number 应用总数据大小

storageStatistics.getTotalSize9+

getTotalSize(): Promise<number>

获取内卡的总空间大小,以promise方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

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

该接口为系统接口,三方应用不支持调用

返回值:

类型 说明
Promise<number> 返回内卡的总空间大小

示例:

  let number = storageStatistics.getTotalSize();
  console.info("getTotalSize successfully:"+ JSON.stringify(number));

storageStatistics.getTotalSize9+

getTotalSize(callback: AsyncCallback<number>): void

获取内卡的总空间大小,以callback方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

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

该接口为系统接口,三方应用不支持调用

参数:

参数名 类型 必填 说明
callback AsyncCallback<number> 获取内卡的总空间大小之后的回调

示例:

  storageStatistics.getTotalSize(function(error, number){
      // do something
      console.info("getTotalSize successfully:"+ JSON.stringify(number));
  });

storageStatistics.getFreeSize9+

getFreeSize(): Promise<number>

获取内卡的可用空间大小,以promise方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

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

该接口为系统接口,三方应用不支持调用

返回值:

类型 说明
Promise<number> 返回内卡的可用空间大小

示例:

  let number = storageStatistics.getFreeSize();
  console.info("getFreeSize successfully:"+ JSON.stringify(number));

storageStatistics.getFreeSize9+

getFreeSize(callback: AsyncCallback<number>): void

获取内卡的可用空间大小,以callback方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

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

该接口为系统接口,三方应用不支持调用

参数:

参数名 类型 必填 说明
callback AsyncCallback<number> 获取内卡的可用空间大小之后的回调

示例:

  storageStatistics.getFreeSize(function(error, number){
      // do something
      console.info("getFreeSize successfully:"+ JSON.stringify(number));
  });

storageStatistics.getSystemSize9+

getSystemSize(): Promise<number>

异步获取系统空间大小,以promise方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

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

该接口为系统接口,三方应用不支持调用

返回值:

类型 说明
Promise<number> 返回系统空间大小

示例:

  storageStatistics.getSystemSize().then(function(number){
      console.info("getSystemSize successfully:"+ number);
  }).catch(function(err){
      console.info("getSystemSize failed with error:"+ err);
  });

storageStatistics.getSystemSize9+

getSystemSize(callback: AsyncCallback<number>): void

异步获取系统空间大小,以callback方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

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

该接口为系统接口,三方应用不支持调用

参数:

参数名 类型 必填 说明
callback AsyncCallback<number> 获取系统空间大小之后的回调

示例:

  storageStatistics.getSystemSize(function(error, number){
      // do something
      console.info("getSystemSize successfully:"+ number);
  });

storageStatistics.getUserStorageStats9+

getUserStorageStats(userId?: number): Promise<StorageStats>

异步获取用户各类别数据大小,以promise方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

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

该接口为系统接口,三方应用不支持调用

参数:

参数名 类型 必填 说明
userId number 用户id
确认当前用户:
- 有值:表示指定用户。
- 无值:表示当前用户。

返回值:

类型 说明
Promise<StorageStats> 返回各类别数据大小

示例:

  let userId = 1;
  storageStatistics.getUserStorageStats(userId).then(function(StorageStats){
      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
  }).catch(function(err){
      console.info("getUserStorageStats failed with error:"+ err);
  });

storageStatistics.getUserStorageStats9+

getUserStorageStats(userId?: number, callback: AsyncCallback<StorageStats>): void

异步获取用户各类别数据大小,以callback方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

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

该接口为系统接口,三方应用不支持调用

参数:

参数名 类型 必填 说明
userId number 用户id
确认当前用户:
- 有值:表示指定用户。
- 无值:表示当前用户。
callback AsyncCallback<StorageStats> 返回各类别数据大小之后的回调

示例:

  let userId = 1;
  storageStatistics.getUserStorageStats(userId, function(error, StorageStats){
      // do something
      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
  });

StorageStats9+

属性

系统能力:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics

该接口为系统接口,三方应用不支持调用

名称 类型 可读 可写 说明
total number 内卡总空间大小
audio number 音频数据大小
video number 视频数据大小
image number 图像数据大小
file number 文件数据大小
app number 应用数据大小

你可能感兴趣的鸿蒙文章

harmony 鸿蒙接口

harmony 鸿蒙系统公共事件定义

harmony 鸿蒙系统公共事件定义

harmony 鸿蒙开发说明

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager模块)

harmony 鸿蒙@ohos.distributedBundle (分布式包管理)

harmony 鸿蒙@ohos.bundle (Bundle模块)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

harmony 鸿蒙@ohos.WorkSchedulerExtensionAbility (延迟任务调度回调)

0  赞