Android Development version management, the use of the Packagemanager class

Source: Internet
Author: User

Set the application version number
The application version information is defined in the application's manifest file.
2 properties that must be defined at the same time:
android:versioncode -Integer, which represents the version of the application code relative to the other kind of version number. The value is an integer, so other applications can judge it in program encoding, for example, to check for an upgrade or downgrade relationship. You can set any value on it, but you should ensure that each subsequent published application uses a larger value. Although the system does not enforce this rule, it is standard practice to use the increased numeric value for each subsequent release. As a typical practice, the first version of your release has a versioncode of 1, and then each subsequent release is monotonically incremented, regardless of whether the release is a major or minor release version. This means that the Android:versioncode value does not have to be particularly similar to the user-visible application release version number. At the same time, the application and publishing platform should not present this version value to the user.

android:versionname ---A string value that displays the release version number of the application code to the user. This value is a string, so you can describe the application version in the form of <major>.<minor>.<point>, or in the form identified by any other type of absolute or relative version number. In contrast to Android:versioncode, the system does not intend to use this value for any internal purposes other than to have the application show it to the user. The application publishing platform may resolve Android:versionname values to be displayed to the user. These version-dependent properties are defined in the <manifest> element of the manifest file.

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.example.package.name" 3 Android:versioncode= "2"4 Android:versionname= "1.1"> 5     <ApplicationAndroid:icon= "@drawable/icon"Android:label= "@string/app_name">6         ... 7     </Application> 8 </Manifest>

In the example, note that the Android:versioncode value shows that the current. APK contains the second publication of the application code, and the Android:versionname string behaves as a small successor release.

Android provides an API for applications to query the system for version information. Use the Packagemanager getpackageinfo (java.lang.String, int) method. For example:
1Packagemanager manager=Getpackagemanager ();2 Try {3PackageInfo info = manager.getpackageinfo (getpackagename (), 0);4Appversioncode =Info.versioncode;5Appversionname =Info.versionname;6}Catch(namenotfoundexception e) {7      //TODO auto-generated Catch block8 e.printstacktrace ();9}

Android Development version management, the use of the Packagemanager class

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.