Android version versioncode and versionname

Source: Internet
Author: User
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.