Created
November 22, 2011 16:00
-
-
Save hkurosawa/1386000 to your computer and use it in GitHub Desktop.
Getting VersionCode and VersionName on Android
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 int getVersionCode() { | |
| int versionCode; | |
| try { | |
| PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); | |
| versionCode = pinfo.versionCode; | |
| } catch (NameNotFoundException e) { | |
| versionCode = -1; | |
| } | |
| return versionCode; | |
| } | |
| public String getVersionName() { | |
| String versionName; | |
| try { | |
| PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); | |
| versionName = pinfo.versionName; | |
| } catch (NameNotFoundException e) { | |
| versionName = null; | |
| } | |
| return versionName; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment