0

I want to create an app to find the amount of internal storage used by "Apps", like in the image below? However, I am not sure how to calculate this total programmatically. Is it possible?

Internal App Storage

Leigh
  • 28,765
  • 10
  • 55
  • 103
Deep PCS
  • 11
  • 1

3 Answers3

1

You may take a look at the details about StorageStatsManager.queryStatsForPackage

https://developer.android.com/reference/android/app/usage/StorageStatsManager.html#queryStatsForPackage(java.util.UUID,%20java.lang.String,%20android.os.UserHandle)

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.

some1
  • 857
  • 5
  • 11
0

Not sure if the best solution but you should be able to traverse through folders and accumulate their sizes. Apps are typically stored in:

Internal/SD card -> Android
Community
  • 1
  • 1
Kia
  • 124
  • 1
  • 1
  • 10
0

Below code will be useful

PackageManager pm = getPackageManager();

Method getPackageSizeInfo = pm.getClass().getMethod(
    "getPackageSizeInfo", String.class, IPackageStatsObserver.class);

getPackageSizeInfo.invoke(pm, "com.android.mms",
    new IPackageStatsObserver.Stub() {

    @Override
    public void onGetStatsCompleted(PackageStats pStats, boolean succeeded)
        throws RemoteException {

        Log.i(TAG, "codeSize: " + pStats.codeSize);
    }
});

More details here

Bertram Gilfoyle
  • 9,899
  • 6
  • 42
  • 67