5

I'm trying to display versionName using below code

PackageManager pkm = getPackageManager();
PackageInfo pki = pkm.getPackageInfo("com.example", PackageManager.GET_CONFIGURATIONS);
String tempCurrentVersion = pki.versionName;

But I'm getting exception at PackageManager.GET_CONFIGURATIONS as NameNotFoundException

Please tell me how i can solve this issue.

Thanks

Richard Ev
  • 52,939
  • 59
  • 191
  • 278
praveenb
  • 10,549
  • 14
  • 61
  • 83
  • Looks like it is necessary to use try-catch, to prevent NameNotFoundException error. This solution works for me: https://stackoverflow.com/questions/6728906/packageinfo-versioncode-and-versionname-null-on-phone-but-works-on-emulator . – joshas Jan 23 '12 at 23:00

2 Answers2

1

I use this is my app and it works correctly.

String mVersion = this.getPackageManager().getPackageInfo(
    "com.safeneighborhood", 0).versionName;

If that doesn't work make sure your package name is correct. There aren't any special permissions for this.

Robby Pond
  • 73,164
  • 16
  • 126
  • 119
  • 3
    I get a compile-time error of `Unhandled exception type PackageManager.NameNotFoundException` using this approach. – Richard Ev Sep 03 '11 at 10:45
0

One really annoying time that I ran into this error was because the package name for the app that I was trying to find/intent over to had hidden characters in the text that I copied. Just to be careful retype out your package name or do a log to see what package name you are really looking for as it might not be what you think.

Chris Klingler
  • 5,258
  • 2
  • 37
  • 43