I registered in the gradle version of the application, how can I now programmatically find out the version of this application? (for example, I need to find out the version in the Activity , which could be displayed in the UI version of this application).
2 answers
Found a solution to find out the version of the application, you can use this code:
int versionCode = BuildConfig.VERSION_CODE; String versionName = BuildConfig.VERSION_NAME; |
Try this:
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); String version = pInfo.versionName; int verCode = pInfo.versionCode; - I get unhandled exception: android.content.pm.PackgeManager.NameNotFoundException - Lucky_girl
- I understand that this code can be used when the application version is written in the manifest. - Lucky_girl
- @Lucky_girl, yes, I did not carefully read the question) - Ksenia
|