Android version versioncode and versionname
Androidmanifest. XML is a required file in every android program. It is located in the root directory of the entire project, describing components exposed in the package (activities, services, etc.), their respective implementation classes, various data that can be processed and startup locations. In addition to declaring activities, contentproviders, services, and intent receivers in the program, you can also specify permissions and instrumentation (Security Control and testing ). The androidmanifest. xml file defines the global configuration information, version, required permissions, and activity structure of the software.
The version number has two values:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.xxx.xxx" android:versionCode="2" android:versionName="1.1"> ......
Versioncode is used by the device program to identify the version (upgrade). It must be an integer representing the number of times the app has been updated.
Versionname is for users, and can be written to versions 1.1, 1.2, and so on.
There is another question: How do I read this value when the app needs to proofread the version?
1. Read manifest. xml
Packagemanager PM = context. getpackagemanager (); // context indicates the context of the current activity.
Packageinfo Pi = PM. getpackageinfo (context. getpackagename (), 0); version = pi. versionname;
2. Define Android: versionname = "@ string/app_versionname" and
Res/values/strings. xml defines a string item with the same name: <string name = "app_versionname"> 1.1 </string>