Android Get SN serial number

Source: Internet
Author: User

One, command line:
Test code:

    New Handler () {        @Override        publicvoid  handlemessage (Message msg) {            LOG.D ( "Getsnnumbers", "SN:" + msg.obj.toString ());        }    ;     New Thread (new  getserialnonumbers (Mhandler));    Snthread.start ();

Class:

    Private Static classGetserialnonumbersImplementsRunnable {Handler mhandler; FinalString serialnostr = "[Ro.boot.serialno]"; Getserialnonumbers (Handler Handler) { This. Mhandler =handler; }         Public voidrun () {Try{Process P= Runtime.getruntime (). EXEC ("Getprop");                P.waitfor (); BufferedReader Stdinput=NewBufferedReader (NewInputStreamReader (P.getinputstream ())); String Temp= "";  while(temp = Stdinput.readline ())! =NULL) {                    if(Temp.contains (serialnostr)) {Temp.replaceall (" ", ""); intindex =Temp.indexof (SERIALNOSTR); Temp= temp.substring (index + 20); Temp= temp.substring (1, Temp.length ()-1); LOG.D ("Getserialnonumbers", temp); Message msg=NewMessage (); Msg.obj=temp;                        Mhandler.sendmessage (msg);  Break; }                }            } Catch(IOException e) {e.printstacktrace (); } Catch(interruptedexception e) {e.printstacktrace (); }        }    }

Second, Reflection:

Test code:

    string[] Propertys = {        "Ro.boot.serialno", "Ro.serialno"    };      for (String key:propertys) {        //  String v = android.os.SystemProperties.get (key);        String v = getandroidossystemproperties (key);        LOG.E ("", "get" + key + ":" + v);    }

Method:

    Staticstring Getandroidossystemproperties (String key) {Method Systemproperties_get=NULL;        String ret; Try{systemproperties_get= Class.forName ("Android.os.SystemProperties"). GetMethod ("Get", String.class); if(ret = (String) Systemproperties_get.invoke (NULL, key))! =NULL)                returnret; } Catch(Exception e) {e.printstacktrace (); return NULL; }        return""; }

Android Get SN serial number

Related Article

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.