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?
Asked
Active
Viewed 1,340 times
3 Answers
1
You may take a look at the details about StorageStatsManager.queryStatsForPackage
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
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