开发者

Name not found exception at PackageManager.GET_CONFIGURATIONS

开发者 https://www.devze.com 2023-01-06 05:17 出处:网络
I\'m trying to display versionName using below code PackageManager pkm = getPackageManager(); PackageInfo pki = pkm.getPackageInfo(\"com.example\", PackageManager.GET_CONFIGURATIONS);

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 NameN开发者_开发知识库otFoundException

Please tell me how i can solve this issue.

Thanks


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 .


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消