i just want to show list of all installed application name with cache size. Cache size must be same as native setting application show in android device.
i able to list all installed application pkg name but can't calculate same cache size which native setting application show(i m talking about that place where clear cache option in setting).
pkNames = getPackageManager().getInstalledPackages(0);
ArrayAdapter<PackageInfo> adapter = new ArrayAdapter<PackageInfo>(this,
android.R.layout.simple_list_item_1, pkNames);
final PackageManager pm = getPackageManager();
for(int i =0;i<pkNames.size();i++)
{
ApplicationInfo applicationInfo = pm.getApplicationInfo(pkNames.get(i).packageName.toString(), 0);
File file = new File(applicationInfo.publicSourceDir);
long size = file.length();
System.out.println("application name == "+pkNames.get(i).packageName.toString()+" ,and size of cache is == "+size(this, size));
}
I use this code but it will give me .apk size of that application. :( Please help thanks in advance.
Locate the application cache folder into memory in following path
"/data/data/com.your.package.appname/cache"
Calculate the application cache size on the disk.
To get the cache size of the Installed Application directly u can not get. As using PackageManger we cant directly get the details regarding installed package size as abstract getPackageSizeInfo method is directly not accessible so by using Java Reflection you can invoke it.It may not work if in future the method name change or any thing changed.
You need to create AIDL IPackageStatsObserver.aidl & PackageStats.aidl which should be in the
android.content.pm
package as you cant directly access them.IPackageStatsObserver.aidl
PackageStats.aidl
IPackageStatsObserver.aidl & PackageStats.aidl both keep it in
android.content.pm
package. IDataStatusActivity
AppDetails
xml