Get Version Name with PackageManager
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
/**
* @author Ryan
*
*/
public class Reflection {
public static String getVersionName ( Context context ) {
try {
ComponentName comp = new ComponentName ( context, Reflection.class );
PackageInfo pinfo = context.getPackageManager ().getPackageInfo ( comp.getPackageName (), 0 );
return pinfo.versionName;
} catch ( NameNotFoundException e ) {
return null;
}
}
}
Related examples in the same category