7

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,

Will Tate
  • 33,439
  • 9
  • 77
  • 71
Ajay Singh
  • 1,611
  • 3
  • 22
  • 29
  • possible duplicate of [Android, get app size](http://stackoverflow.com/questions/4065149/android-get-app-size) – Robby Pond Mar 15 '11 at 17:33

2 Answers2

12

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!

Will Tate
  • 33,439
  • 9
  • 77
  • 71
2

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.

Paolo Rovelli
  • 9,396
  • 2
  • 58
  • 37