Here you can find the source of GetVersionName(final Context context)
public static String GetVersionName(final Context context)
//package com.java2s; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; public class Main { public static String GetVersionName(final Context context) { String versionName = "1.0.0"; PackageManager packageManager = context.getPackageManager(); try {/*from w ww . j a v a 2 s . com*/ PackageInfo packageInfo = packageManager.getPackageInfo( context.getPackageName(), 0); versionName = packageInfo.versionName; } catch (Exception e) { e.printStackTrace(); } return versionName; } }