Created
February 22, 2014 11:02
-
-
Save SeanZoR/9152066 to your computer and use it in GitHub Desktop.
Android - Get application version code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int getVersionCode(Context ctx) { | |
int versionCode = 0; | |
try { | |
PackageInfo pInfo = ctx.getPackageManager().getPackageInfo( | |
ctx.getPackageName(), 0); | |
versionCode = pInfo.versionCode; | |
} catch (PackageManager.NameNotFoundException e) { | |
e.printStackTrace(); | |
} | |
return versionCode; | |
} |
Correct me if I'm wrong. Is it applicable here the Payroll system?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was looking for this one and ended up here , Its been 3 years 🚶♂️
Let me update this for future references ,
If you're using the Gradle plugin/Android Studio, as of version 0.7.0 ( Right now it is 2.1.0 ), version code and version name are available statically in BuildConfig:
No Context object needed!
Just make sure to specify them in your build.gradle file instead of the AndroidManifest.xml.