Android examples for android.content.pm:PackageManager
get Version Name from PackageManager
import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager; import java.text.SimpleDateFormat; import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ public static String getVersionName(Context context) { PackageManager packageManager = context.getPackageManager(); PackageInfo packInfo = null;//from www . j a v a 2 s .co m try { packInfo = packageManager.getPackageInfo( context.getPackageName(), 0); } catch (NameNotFoundException e) { e.printStackTrace(); } return packInfo == null ? "" : packInfo.versionName; } }