App Storage Statistics

icon-note.gif NOTE

  • The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • API version 9 is a canary release for trial use. The APIs of this version may be unstable.

Modules to Import

import storagestatistics from "@ohos.storageStatistics";

storagestatistics.getTotalSizeOfVolume

getTotalSizeOfVolume(volumeUuid: string): Promise<number>

Asynchronously obtains the total space of the specified volume. This API uses a promise to return the result.

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

  • Parameters
Name Type Mandatory Description
volumeUuid string Yes UUID of the volume.
  • Return value
Type Description
Promise<number> Promise used to return the total space of the volume.
  • Example

    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

Asynchronously obtains the total space of the specified volume. This API uses a callback to return the result.

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

  • Parameters
Name Type Mandatory Description
volumeUuid string Yes UUID of the volume.
callback callback:AsyncCallback<number> Yes Callback invoked to return the total space of the volume.
  • Example

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

storagestatistics.getFreeSizeOfVolume

getFreeSizeOfVolume(volumeUuid: string): Promise<number>

Asynchronously obtains the available space of the specified volume. This API uses a promise to return the result.

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

  • Parameters
Name Type Mandatory Description
volumeUuid string Yes UUID of the volume.
  • Return value
Type Description
Promise<number> Promise used to return the available space of the volume.
  • Example

    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

Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result.

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

  • Parameters
Name Type Mandatory Description
volumeUuid string Yes UUID of the volume.
callback callback:AsyncCallback<number> Yes Callback invoked to return the available space of the volume.
  • Example

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

storagestatistics.getBundleStats9+

getBundleStats(packageName: string): Promise<BundleStats>

Asynchronously obtains app information. This API uses a promise to return the result.

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

  • Parameters
Name Type Mandatory Description
packageName string Yes Bundle name of the app.
  • Return value
Type Description
Promise<Bundlestats> Promise used to return the app information.
  • Example

    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

Asynchronously obtains app information. This API uses a callback to return the result.

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

  • Parameters
Name Type Mandatory Description
packageName string Yes Bundle name of the app.
callback callback:AsyncCallback<Bundlestats> Yes Callback invoked to return the app information.
  • Example

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

BundleStats9+

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

Attributes

Name Type Description
appSize9+ number Size of the app.
cacheSize9+ number Cache size of the app.
dataSize9+ number Total data size of the app.