Code to get information such as Android version

Source: Internet
Author: User
<span id="Label3"></p><p><p>My Phone's about the phone interface:</p></p><p><p><br></p></p><p><p>Description</p></p><p><p>The phone model, android version, software version through the system build class, the processor information, kernel version by reading the system files, baseband version information through Reflection.</p></p><p><p><br></p></p><p><p>Source:</p></p><p><p></p></p><pre name="code" class="java">Package Com.example.shen.phoneinfo;import Android.app.activity;import android.support.v7.app.ActionBarActivity; Import Android.os.bundle;import android.util.log;import Android.view.menu;import Android.view.menuitem;import Java.io.bufferedreader;import Java.io.filenotfoundexception;import Java.io.filereader;import java.io.IOException; Import Java.io.inputstream;import Java.io.inputstreamreader;import Java.lang.reflect.method;public class Mainactivity extends Activity {@Override protected void onCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); LOG.E ("phoneinfo", "MODEL:" + android.os.Build.MODEL); LOG.E ("phoneinfo", "CPUInfo:" +getcpuinfo ()); LOG.E ("phoneinfo", "version_release:" +android.os.build.version.release); LOG.E ("phoneinfo", "version_sdk:" +android.os.build.version.sdk_int + "); LOG.E ("phoneinfo", "basebandversion:" +getbasebandversion ()); LOG.E ("phoneinfo", "Kernelversion: "+getkernelversion ()); LOG.E ("phoneinfo", "ID:" + android.os.Build.ID); /** * Get Processor information * @return string */public string getcpuinfo () {try {filereader file Reader = new FileReader ("/proc/cpuinfo"); BufferedReader BufferedReader = new BufferedReader (filereader); String info; While (info = Bufferedreader.readline ()) = Null) {string[] array = info.split (":"); If (array[0].trim (). equals ("Hardware")) {return array[1]; }}} catch (filenotfoundexception e) {e.printstacktrace (); } catch (ioexception E) {e.printstacktrace (); } return null; /** * Get Baseband version * @return string */public string getbasebandversion () {string-version = ""; Try {Class clazz= Class.forName ("android.os.SystemProperties"); Object Object = clazz.newinstance (); method = Clazz.getmethod ("get", new class[]{string.class, string.class}); Object result = Method.invoke (object, new object[]{"gsm.version.baseband", "no message"}); Version = (String) result; } catch (Exception E) {} return version; /** * Get Kernel version * @return string */public string getkernelversion () {process process = null; String kernelversion = ""; Try {process = runtime.getruntime (). exec ("cat/proc/version"); } catch (ioexception E) {e.printstacktrace (); } inputstream InputStream = Process.getinputstream (); InputStreamReader InputStreamReader = new InputStreamReader (inputstream); BufferedReader BufferedReader = new BufferedReader (inputstreamreader, 8 * 1024); String result = ""; String info; Try {while (info = bufferedreader.readline ()) = null) { Result + = info; }} catch (ioexception e) {e.printstacktrace (); The try {if (result! = "") {String keyword = "version"; int index = Result.indexof (keyword); info = result.substring (index + keyword.length ()); index = Info.indexof (""); Kernelversion = info.substring (0, index); }} catch (indexoutofboundsexception e) {e.printstacktrace (); } return kernelversion; }}</pre><p><p></p></p><p><p><br></p></p>Operation Result:<br><br><p><p><br></p></p><p><p>/proc/cpuinfo file</p></p><p><p><br></p></p><p><p><br></p></p><p><p>/proc/version file</p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>Code to get information such as Android version</p></p></span>

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.