The versionName value in your project manifest file is a 'friendly' version number that is displayed to the user on the market screen and in the application list. The versionCode value is the integer that allows you to version and publish updates to your app on the market (refer to the official documentation on Versioning Your Applications).
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.androidelements.myProject" android:versionCode="1" android:versionName="1.0.0">
You might want to display the version name in your app, on a splash or about screen perhaps. To do this you need to use the PackageInfo class, here's how...
Add the following imports:
import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException;
Use the following code to display the value in a TextView:
String versionName = ""; try { final PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); versionName = packageInfo.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } TextView tv = (TextView) findViewById(R.id.tvVersion); tv.setText(versionName);
0 comments:
Post a Comment