Name not found exception at PackageManager.GET_CONFIGURATIONS

13,120

Solution 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.

Solution 2

Looks like it is necessary to use try-catch, to prevent NameNotFoundException error. This solution works for me: PackageInfo versionCode and versionName null on phone, but works on emulator .

Share:
13,120

Related videos on Youtube

praveenb
Author by

praveenb

Android Developer Programs Engineer @ PCCS http://www.praveenboyalapalli.com/

Updated on June 04, 2022

Comments

  • praveenb
    praveenb almost 2 years

    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
    Richard Ev over 12 years
    I get a compile-time error of Unhandled exception type PackageManager.NameNotFoundException using this approach.