NEEDED: I'm just trying to get the size of the occupied cache for each application that is installed on my phone.
MY APPROACH:
PackageManager packageManager = getPackageManager(); List<ApplicationInfo> packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo packageInfo : packages) { try { Context mContext = createPackageContext(packageInfo.packageName, CONTEXT_IGNORE_SECURITY); File cacheDirectory = mContext.getCacheDir(); if(cacheDirectory==null) { cacheArrayList.add("0"); } else { cacheArrayList.add(String.valueOf(cacheDirectory.length()/1024)); } } catch (NameNotFoundException e) { e.printStackTrace(); } }
RESULT: If the directory is null, it returns 0 (as a condition). But if the directory exists, its return 4 Kb always. I checked my application cache by doing this process:
Settings: → Programs: → ApplicationName
But I found 0B there.
Why can someone explain his case? and how to get the exact cache size?
user1982396
source share