Skip to content

Most visited

Recently visited

navigation

StorageStatsManager

public class StorageStatsManager
extends Object

java.lang.Object
   ↳ android.app.usage.StorageStatsManager


Access to detailed storage statistics. This provides a summary of how apps, users, and external/shared storage is utilizing disk space.

Note: no permissions are required when calling these APIs for your own package or UID. However, requesting details for any other package requires the android.Manifest.permission#PACKAGE_USAGE_STATS permission, which is a system-level permission that will not be granted to normal apps. Declaring that permission expresses your intention to use this API and an end user can then choose to grant this permission through the Settings application.

Instances of this class must be obtained using Context.getSystemService(Class) with the argument StorageStatsManager.class or Context.getSystemService(String) with the argument Context.STORAGE_STATS_SERVICE.

Summary

Public methods

long getFreeBytes(UUID storageUuid)

Return the free space on the requested storage volume.

long getTotalBytes(UUID storageUuid)

Return the total size of the underlying physical media that is hosting this storage volume.

ExternalStorageStats queryExternalStatsForUser(UUID storageUuid, UserHandle user)

Return shared/external storage statistics for a specific UserHandle on the requested storage volume.

StorageStats queryStatsForPackage(UUID storageUuid, String packageName, UserHandle user)

Return storage statistics for a specific package on the requested storage volume.

StorageStats queryStatsForUid(UUID storageUuid, int uid)

Return storage statistics for a specific UID on the requested storage volume.

StorageStats queryStatsForUser(UUID storageUuid, UserHandle user)

Return storage statistics for a specific UserHandle on the requested storage volume.

Inherited methods

From class java.lang.Object

Public methods

getFreeBytes

added in API level 26
long getFreeBytes (UUID storageUuid)

Return the free space on the requested storage volume.

This value is best suited for visual display to end users, since it's designed to reflect both unused space and and cached space that could be reclaimed by the system.

Apps making logical decisions about disk space should always use ERROR(/StorageManager#getAllocatableBytes(UUID, int)) instead of this value.

This method may take several seconds to complete, so it should only be called from a worker thread.

Value is a non-negative number of bytes.

Parameters
storageUuid UUID: the UUID of the storage volume you're interested in, such as UUID_DEFAULT.

This value must never be null.

Returns
long

Value is a non-negative number of bytes.

Throws
IOException when the storage device isn't present.

getTotalBytes

added in API level 26
long getTotalBytes (UUID storageUuid)

Return the total size of the underlying physical media that is hosting this storage volume.

This value is best suited for visual display to end users, since it's designed to reflect the total storage size advertised in a retail environment.

Apps making logical decisions about disk space should always use getTotalSpace() instead of this value.

This method may take several seconds to complete, so it should only be called from a worker thread.

Value is a non-negative number of bytes.

Parameters
storageUuid UUID: the UUID of the storage volume you're interested in, such as UUID_DEFAULT.

This value must never be null.

Returns
long

Value is a non-negative number of bytes.

Throws
IOException when the storage device isn't present.

queryExternalStatsForUser

added in API level 26
ExternalStorageStats queryExternalStatsForUser (UUID storageUuid, 
                UserHandle user)

Return shared/external storage statistics for a specific UserHandle on the requested storage volume.

Note: this API requires the android.Manifest.permission#PACKAGE_USAGE_STATS permission, which is a system-level permission that will not be granted to normal apps. Declaring that permission expresses your intention to use this API and an end user can then choose to grant this permission through the Settings application.

This method may take several seconds to complete, so it should only be called from a worker thread.

Parameters
storageUuid UUID: the UUID of the storage volume you're interested in, such as UUID_DEFAULT.

This value must never be null.

user UserHandle

This value must never be null.

Returns
ExternalStorageStats

This value will never be null.

Throws
IOException when the storage device isn't present.

See also:

queryStatsForPackage

added in API level 26
StorageStats queryStatsForPackage (UUID storageUuid, 
                String packageName, 
                UserHandle user)

Return storage statistics for a specific package on the requested storage volume.

Note: no permissions are required when calling this API for your own package. However, requesting details for any other package requires the android.Manifest.permission#PACKAGE_USAGE_STATS permission, which is a system-level permission that will not be granted to normal apps. Declaring that permission expresses your intention to use this API and an end user can then choose to grant this permission through the Settings application.

Note: if the requested package uses the android:sharedUserId manifest feature, this call will be forced into a slower manual calculation path. If possible, consider always using queryStatsForUid(UUID, int), which is typically faster.

This method may take several seconds to complete, so it should only be called from a worker thread.

Parameters
storageUuid UUID: the UUID of the storage volume you're interested in, such as UUID_DEFAULT.

This value must never be null.

packageName String: the package name you're interested in.

This value must never be null.

user UserHandle: the user you're interested in.

This value must never be null.

Returns
StorageStats

This value will never be null.

Throws
when the requested package name isn't installed for the requested user.
IOException when the storage device isn't present.
PackageManager.NameNotFoundException

See also:

queryStatsForUid

added in API level 26
StorageStats queryStatsForUid (UUID storageUuid, 
                int uid)

Return storage statistics for a specific UID on the requested storage volume.

Note: no permissions are required when calling this API for your own UID. However, requesting details for any other UID requires the android.Manifest.permission#PACKAGE_USAGE_STATS permission, which is a system-level permission that will not be granted to normal apps. Declaring that permission expresses your intention to use this API and an end user can then choose to grant this permission through the Settings application.

This method may take several seconds to complete, so it should only be called from a worker thread.

Parameters
storageUuid UUID: the UUID of the storage volume you're interested in, such as UUID_DEFAULT.

This value must never be null.

uid int: the UID you're interested in.

Returns
StorageStats

This value will never be null.

Throws
IOException when the storage device isn't present.

See also:

queryStatsForUser

added in API level 26
StorageStats queryStatsForUser (UUID storageUuid, 
                UserHandle user)

Return storage statistics for a specific UserHandle on the requested storage volume.

Note: this API requires the android.Manifest.permission#PACKAGE_USAGE_STATS permission, which is a system-level permission that will not be granted to normal apps. Declaring that permission expresses your intention to use this API and an end user can then choose to grant this permission through the Settings application.

This method may take several seconds to complete, so it should only be called from a worker thread.

Parameters
storageUuid UUID: the UUID of the storage volume you're interested in, such as UUID_DEFAULT.

This value must never be null.

user UserHandle: the user you're interested in.

This value must never be null.

Returns
StorageStats

This value will never be null.

Throws
IOException when the storage device isn't present.

See also:

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.