Is there a way for my app to know the android:versionCode from AndroidManifest.xml or do I have to create a separate constant in one of my classes?
The version code is an incremental integer value that represents the version of the application code. The version name is a string value that represents the “friendly” version name displayed to the users.
Once in Settings, tap Apps and notifications (or your phone manufacturer's name it). When you're in there, tap See all xyz apps (where xyz is the number of apps you have installed). Now scroll down until you find the app you want to find the version for. Then tap it in the list.
I put this in my subclassed android.app.Application but you can use it anywhere you have a context. Just change getPackageManager() to context.getPackageManager().
public int getVersion() { int v = 0; try { v = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; } catch (NameNotFoundException e) { // Huh? Really? } return v; }
Yes, you can access this information via PackageManager.getPackageInfo
Also, see details about versioning in the documentation
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