73
67

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Android】アプリのバージョン名とバージョン番号を取得する

Last updated at Posted at 2013-11-23
	/**
	 * バージョンコードを取得する
	 *
	 * @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;
73
67
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
73
67

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?