Android obtains the current software version number and version name.
/*** Obtain the local software version */public static int getLocalVersion (Context ctx) {int localVersion = 0; try {PackageInfo packageInfo = ctx. getApplicationContext (). getPackageManager (). getPackageInfo (ctx. getPackageName (), 0); localVersion = packageInfo. versionCode; LogUtil. d ("TAG", "version of the software .. "+ LocalVersion);} catch (NameNotFoundException e) {e. printStackTrace ();} return localVersion;}/*** get the local software version name */public static String getLocalVersionName (Context ctx) {String localVersion = ""; try {PackageInfo packageInfo = ctx. getApplicationContext (). getPackageManager (). getPackageInfo (ctx. getPackageName (), 0); localVersion = packageInfo. versionName; LogUtil. d ("TAG", "version of the software .. "+ LocalVersion);} catch (NameNotFoundException e) {e. printStackTrace ();} return localVersion ;}