Gets the version name in the manifest file - Android App

Android examples for App:APK File

Description

Gets the version name in the manifest file

Demo Code

import com.sun.istack.internal.Nullable;

import android.content.Context;
import android.content.pm.PackageManager;

public class Main {
  /**/*ww  w.  j  a v  a 2s. c o m*/
   * Gets the version name in the manifest file
   * 
   * @param context
   *          the context
   * @return version
   */

  public static String getVersion(@Nullable Context context) {
    String version = "Unknown";
    if (context == null)
      return version;
    try {
      version = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException ex) {
    }
    return version;
  }
}

Related Tutorials