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 .
Related videos on Youtube
Author by
praveenb
Android Developer Programs Engineer @ PCCS http://www.praveenboyalapalli.com/
Updated on June 04, 2022Comments
-
praveenb almost 2 years
I'm trying to display
versionName
using below codePackageManager pkm = getPackageManager(); PackageInfo pki = pkm.getPackageInfo("com.example", PackageManager.GET_CONFIGURATIONS); String tempCurrentVersion = pki.versionName;
But I'm getting exception at
PackageManager.GET_CONFIGURATIONS
asNameNotFoundException
Please tell me how i can solve this issue.
Thanks
-
Richard Ev over 12 yearsI get a compile-time error of
Unhandled exception type PackageManager.NameNotFoundException
using this approach.