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)
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top