Android examples for android.content:Context
get Current Version Name from Context
import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; public class Main { public static String getCurrentVersionName(Context context) { String currentVersionName = ""; try {//from www .j a va 2 s . c o m PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); currentVersionName = pi.versionName; if (currentVersionName == null || currentVersionName.length() <= 0) { currentVersionName = "1.0.0"; } } catch (Exception e) { currentVersionName = "1.0.0"; } return currentVersionName; } }