Read the name and version number of the ANDROID Application in the program.

Source: Internet
Author: User

In ANDROID applications, we often need to display the program name and version number in the Application Introduction and description. Of course, we can write it directly in the code using hard encoding, but it is not very convenient to change every version upgrade. So how can I read the name and version number of the ANDROID app? Www.2cto.com is actually very simple. There is a Package Manager in the ANDROID system, and we will use it to complete this task. [Java] PackageInfo pkg = getPackageManager (). getPackageInfo (getApplication (). getPackageName (), 0); String appName = pkg. applicationInfo. loadLabel (getPackageManager ()). toString (); String versionName = pkg. versionName; appName is the name of the ANDROID application. VersionName is the current version number of the ANDROID application. It corresponds to the versionName attribute in the AndroidManifest. xml file.

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.