0

I am trying to get the install time of all the applications installed in my Android Phone with OS 2.2, but I am not getting exactly the time they were installed, instead I am getting today's date and time. I know that I can get it thorough:

packageManager.getPackageInfo(packageName, 0).firstInstallTime;

but this is available for API level 9 onwards and I need to get firstInstallTime in API level 8.

Searching revealed me another way of achieving it, but it gives today's date, instead of app's install date.

PackageManager pm = context.getPackageManager();
ApplicationInfo appInfo = pm.getApplicationInfo("app.package.name", 0);
String app = appInfo.sourceDir;
long installedTime = new File(app).lastModified();

Any idea how can Iget my desired result? Please update. Any help is appreciated.

Usama Sarwar
  • 8,922
  • 7
  • 54
  • 80
  • Please try this http://stackoverflow.com/questions/3127489/install-time-for-android-application – madhus Feb 07 '13 at 12:51

1 Answers1

-1

Try this block. This solves your problem

PackageManager pm = getApplicationContext().getPackageManager();
         try {
            PackageInfo info = pm.getPackageInfo("com.google.android.googlequicksearchbox", 0);
             Field field = PackageInfo.class.getField("firstInstallTime");
             long timestamp = field.getLong(info);
             Date date = new Date(timestamp);
             Log.e("DATE", date + "");
        } catch (NameNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SecurityException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IllegalArgumentException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (NoSuchFieldException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IllegalAccessException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
detay34
  • 44
  • 6