/**
* バージョンコードを取得する
*
* @param context
* @return
*/
public static int getVersionCode(Context context){
PackageManager pm = context.getPackageManager();
int versionCode = 0;
try{
PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
versionCode = packageInfo.versionCode;
}catch(NameNotFoundException e){
e.printStackTrace();
}
return versionCode;
}
/**
* バージョン名を取得する
*
* @param context
* @return
*/
public static String getVersionName(Context context){
PackageManager pm = context.getPackageManager();
String versionName = "";
try{
PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
versionName = packageInfo.versionName;
}catch(NameNotFoundException e){
e.printStackTrace();
}
return versionName;
More than 5 years have passed since last update.
【Android】アプリのバージョン名とバージョン番号を取得する
Last updated at Posted at 2013-11-23
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme