Get Android version information and program version number

Source: Internet
Author: User

 Public classMainactivityextendsactionbaractivity {PrivateTextView Mtextview; @Overrideprotected voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stub        Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); //Gets the current project version numberMtextview =(TextView) Findviewbyid (R.ID.TEXTVIEW1); Try{getversionname (); } Catch(Exception e) {//TODO auto-generated Catch blockE.printstacktrace (); }        //Android System version informationString model_version= "Android system version info:" + Android.os.Build.MODEL + ", API" + Android.os.Build.VERSION.SDK + ", an Droid "+Android.os.Build.VERSION.RELEASE; //Display Information    Try{Mtextview.settext ("Current Program version:" + getversionname () + "\ n" +model_version); } Catch(Exception e) {//TODO auto-generated Catch blockE.printstacktrace (); }    }      PrivateString Getversionname ()throwsException {//get an instance of PackagemanagerPackagemanager Packagemanager =Getpackagemanager (); //Getpackagename () is the package name of your current class, and 0 means to get version informationPackageInfo packinfo = Packagemanager.getpackageinfo (Getpackagename (), 0); String version=Packinfo.versionname; returnversion; }
}

Get Android version information and program version number

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.