IMEI in Android

Source: Internet
Author: User

The IMEI: International Mobile Equipment Identification Number (IMEI) identifies mobile devices. It is stored in mobile devices and can be used to monitor stolen or invalid mobile devices. IMEI can be found by typing "* #06 #" on mobile devices of different manufacturers. (different manufacturers may have different input content on their mobile phones ). The total length is 15 digits, and each digit only uses 0 ~ 9 ).

The method to obtain IMEI is as follows: 1) Use telephonymanager. getdeviceid (); 2) if the first method cannot be obtained, you can use wifimanager. getconnectinfo (). getmacaddress (): remove it. 3) use Java's UUID. randomuuid (), remove.

Private string getimei (){
Telephonymanager = (telephonymanager) getsystemservice (context. telephony_service );
String IMEI = telephonymanager. getdeviceid ();
Boolean isimei = check (IMEI );
If (! Textutils. isempty (IMEI )){
Isimei = check (IMEI );
If (isimei)
Return IMEI;
}

If (textutils. isempty (IMEI) |! Isimei ){
// Start get MAC address
Wifimanager wifiman = (wifimanager) getsystemservice (context. wifi_service );
If (wifiman! = NULL ){
Wifiinfo wifiinf = wifiman. getconnectioninfo ();
If (wifiinf! = NULL & wifiinf. getmacaddress ()! = NULL) {// 48 bits, such as fa: 34: 7c: 6d: e4: D7
IMEI = wifiinf. getmacaddress (). replaceall (":","");
Return IMEI;
}
}
}
If (textutils. isempty (IMEI) |! Isimei ){
IMEI = UUID. randomuuid (). tostring (). replaceall ("-", ""); // UUID universal unique identifier (universally unique identifier) (128 bits, such as identifier)
}
Return IMEI;
}

In addition, you can obtain the mobile phone model code by using build. model.

// Build. Model (mobile phone model, such as motoa953)
Private string getdevicemodel (){
Build BD = new build ();
String Model = BD. model;
Return Model;
}

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.