Last active
August 29, 2015 14:13
-
-
Save crowjdh/8ffc802fcf4c6245deac to your computer and use it in GitHub Desktop.
Way to get app's version information
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
import android.content.Context; | |
import android.content.pm.PackageInfo; | |
import android.content.pm.PackageManager; | |
/** | |
* Created by Dongheyon Jeong on 15. 1. 20. | |
* | |
* AppInfo | |
* 앱의 일반적인 정보를 제공하는 클래스 | |
*/ | |
public class AppInfo { | |
public static final int INVALID_VERSION_CODE = -1; | |
public static int getVersionCode(Context context) { | |
PackageInfo pInfo; | |
try { | |
if (context.getPackageManager() != null) { | |
pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); | |
return pInfo.versionCode; | |
} | |
} catch (PackageManager.NameNotFoundException e) { | |
e.printStackTrace(); | |
} | |
return INVALID_VERSION_CODE; | |
} | |
public static String getVersionName(Context context) { | |
PackageInfo pInfo; | |
try { | |
if (context.getPackageManager() != null) { | |
pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); | |
return pInfo.versionName; | |
} | |
} catch (PackageManager.NameNotFoundException e) { | |
e.printStackTrace(); | |
} | |
return ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment