Question

Hi I am getting this strange error in my app when asking for first installation time using packageinfo! but only for some devices the error is rare and not often. why is it happening and is there a workaround?

        PackageManager manager = this.getPackageManager();
        info = manager.getPackageInfo(this.getPackageName(), 0);
        vPname = info.packageName;
        vName = info.versionName;
        vVers = info.versionCode;
        installDate = info.firstInstallTime;

gives

java.lang.NoSuchFieldError: android.content.pm.PackageInfo.firstInstallTime

minSdkVersion="7"

a list of some devices which returns error:

  • Optimus One (thunderg)
  • LG-P920 (p920)
  • Defy (umts_jordan)
  • Infuse (SGH-I997)
Was it helpful?

Solution

that's because "firstInstallTime" was introduced on API 9 (gingerbread) and above:

http://developer.android.com/reference/android/content/pm/PackageInfo.html#firstInstallTime

in order to avoid such errors, it is advised to run a LINT check (using the "V" button near the run button, for example). LINT has plenty of errors and warnings that could help you get a better code. you can even make it check for problems on each save operation.

Of course, it has bugs and missing checks too, even for this matter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top