Last active
December 14, 2015 10:18
-
-
Save ebridges/5070799 to your computer and use it in GitHub Desktop.
Get the versionCode & versionName attributes from `AndroidManifest.xml` at runtime
This file contains 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
import android.app.Activity; | |
// http://stackoverflow.com/questions/3874775/detect-my-apps-own-androidversioncode-at-run-time | |
public class GetVersion { | |
public static Integer getVersion(Activity activity) { | |
Integer version = 0; | |
try { | |
version = activity.getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; | |
} catch (NameNotFoundException e) { | |
// Todo: handle | |
} | |
return version; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment