Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name not found exception at 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 NameNotFoundException

Please tell me how i can solve this issue.

Thanks

like image 931
praveenb Avatar asked Jul 07 '10 22:07

praveenb


People also ask

Why we get namenotfoundexception when calling getpackageinfo on Android 11?

There is one behaviour change in Android API level 30because of which we get NameNotFoundException when we call getPackageInfo on Android 11 even if the app/package app is installed on user's device. From Android API 30, we need to specify the package name in manifest in order to check if that package is installed on user's device.

How do I enable package configuration in Visual Studio?

To enable package configurations. In the Package Configurations Organizer dialog box, select Enable Package Configurations, and then click Add. On the welcome page of the Package Configuration Wizard, click Next. On the Select Configuration Type page, verify that the Configuration type is set to XML configuration file.

Why add-appxpackage failed with HRESULT 0x80073d02?

Add-AppxPackage : Deployment failed with HRESULT: 0x80073D02, The package could not be installed because resources it modifies are currently in use. error 0x80073D02: Unable to install because the following apps need to be closed InputApp_1000.17763.1.0_neutral_neutral_cw5n1h2txyewy.

How do I create an XML configuration file for a package?

In the Package Configurations Organizer dialog box, select Enable Package Configurations and then select Add. On the welcome page of the Package Configuration Wizard, select Next. On the Select Configuration Type page, verify that the Configuration type is set to XML configuration file. On the Select Configuration Type page, select Browse.


2 Answers

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 .

like image 106
joshas Avatar answered Sep 19 '22 02:09

joshas


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.

like image 20
Robby Pond Avatar answered Sep 19 '22 02:09

Robby Pond