0

I want to get the date and time (isn't that important) when the user installed his latest android version on the smartphone. I searched in google and looked after in the Android Reference, but didn'f find anything like that.

My first thought was the class android.os.BUILD but there is nothing.

android.od.BUILD.Time is just the date when the Build was compiled.

Thanks for your help!

4

1 に答える 1

0
private void getAppInstallTime(){
PackageManager pm = getApplicationContext().getPackageManager();
        try {
           PackageInfo info = pm.getPackageInfo("com.example.sample", 0);
            Field field = PackageInfo.class.getField("firstInstallTime");
            long timestamp = field.getLong(info);
            Date date = new Date(timestamp);
            Log.e("DATE", date + "InMillies "+timestamp);
            ApplicationInfo appInfo = pm.getApplicationInfo("com.example.sample", 0);
   String appFile = appInfo.sourceDir;
   long installed = new File(appFile).lastModified();
   Date dateMod = new Date(installed);
   Log.e("Updates","Updated Time"+dateMod+"  time in millies"+installed);
       } 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();
       }
 }
}
于 2013-10-16T16:51:11.717 に答える