Reputation: 1621
In Android, How I can get app installed date and how I can get installed app size.
I am using below code to get app size but it is not correct
List packs = getPackageManager().getInstalledPackages(0);
for(i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
ApplicationInfo appInfo =p.applicationInfo;
long fileSize = new FileInputStream(appInfo.sourceDir).getChannel().size();
}
Please help me.. Thanks,
Upvotes: 7
Views: 8821
Reputation: 9684
For the size of a package you may try the standard "Java way", thus:
ApplicationInfo appInfo = ...;
try{
File file = new File(appInfo.sourceDir);
double size = file.length(); // size in Byte
Log.d(TAG, "Size: " + size + " Byte\n");
} catch( Exception e ) {
//e.printStackTrace();
}
Not sure it gives you a precise estimation of the size, though.
Upvotes: 2
Reputation: 33509
Ajay,
To get the installation date you will want to use the PackageManager
class. More specifically the getPackageInfo()
method. This will return to you a PackageInfo
object which contains firstInstallTime
value.
There does not currently exist a public API to get an application's size as PackageManager.getpackageSizeInfo()
was removed from the API from SDK 0.9 to SDK 1.0. See HERE
Good luck!
Upvotes: 12