Created
August 9, 2012 10:53
-
-
Save ogulcan/3303243 to your computer and use it in GitHub Desktop.
Android Version Name and Code
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
public static String getApplicationVersionString(Context context) { | |
try { | |
PackageManager pm = context.getPackageManager(); | |
PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0); | |
return info.versionName; | |
} catch (Exception e) { | |
e.printStackTrace(); | |
return null; | |
} | |
} | |
public static int getApplicationVersionCode(Context context) { | |
try { | |
PackageManager pm = context.getPackageManager(); | |
int versionCode = pm.getPackageInfo(context.getPackageName(), 0).versionCode; | |
return versionCode; | |
} catch (Exception e) { | |
e.printStackTrace(); | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment