How to get Storage Stats In Android O (API 26)

Brijesh Gupta
Jan 21, 2018 · 2 min read
Android Storage Statistics

Android Stats Manager

From Android O (API 26) StorageStatsManager class is available to Access detailed storage statistics. It provides a summary of how apps, users, and external/shared storage is utilizing disk space.

Android Storage


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 the end user can then choose to grant this permission through the Settings application.

You can easily get Storage Volume Statistics using the following piece of code. It gives you free space on the requested storage volume and the total size of the underlying physical media that is hosting this storage volume.

Query Stats For Package

You can get storage statistics for a specific package on the requested storage volume. To get storage stats for a particular package, you will need UserHandler, UUID and package name.

UUID represents an immutable universally unique identifier (UUID). A UUID represents a 128-bit value.

The following piece of code will fetch the required data:

getAppBytes Return the size of app. This includes APK files, optimized compiler output, and unpacked native libraries.

getDataBytes Return the size of all data. This includes files stored under getDataDir(), getCacheDir(), getCodeCacheDir().

getCacheBytes Return the size of all cached data. This includes files stored under getCacheDir() and getCodeCacheDir().

If you want a demo project or source code on GitHub, check out the following:


Reach Me!

LinkedIn, GitHub

Cashify Engineering

Brijesh Gupta

Written by

Senior Software Engineer — Mobile | Tech Lover | AI | Machine Learning

Cashify Engineering

Cashify Engineering & Data Science

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade