Here you can find the source of getPackageVersion(Context c)
public static String getPackageVersion(Context c)
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Build; import android.util.Log; public class Main { public static String getPackageVersion(Context c) { String packageVersion = ""; try {//from w ww .j a v a2 s . co m PackageInfo pInfo = c.getPackageManager().getPackageInfo( c.getPackageName(), 0); packageVersion += "I have OpenWatch version " + pInfo.versionName; packageVersion += " running on Android API " + String.valueOf(Build.VERSION.SDK_INT) + "."; } catch (PackageManager.NameNotFoundException e) { Log.e("getPackageVersion", "Unable to read PackageName in RegisterApp"); e.printStackTrace(); } return packageVersion; //USER_AGENT += " (Android API " + Build.VERSION.RELEASE + ")"; } }