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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With