Android examples for App:App Information
Obtain application's version name, android:versionName="1.0.0"
import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; public class Main { /**/*from ww w . j ava 2 s . co m*/ * Obtain application's version name,<br> * android:versionName="1.0.0" * * @param context * @return */ public static final String obtainVersionName(Context context) { try { PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return pi.versionName; } catch (NameNotFoundException e) { } return "unknown"; } }