Get version number
import android.content.Context; import android.content.pm.PackageManager.NameNotFoundException; class Main { public static String getVersion(Context context) throws RuntimeException { try { return context.getPackageManager().getPackageInfo( context.getPackageName(), 0).versionName; } catch (NameNotFoundException ex) { throw new RuntimeException("Failed to get app version"); } } }