0

I am developing an app, in which i need to display the total caches of all apps combined, in my TextView. how do i do that?

i have found this snippet from an answer

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();
}
}
Community
  • 1
  • 1
MaggotSauceYumYum
  • 402
  • 1
  • 5
  • 23

0 Answers0