How to get IMEI number in Android

Source: Internet
Author: User

1) within the telephony framework, you can directly use the interface provided by the Gsmphone or Geminiphone.
Previous versions of KK:
IMEI (International Mobile Equipment Identity) is an international mobile device identity code, in a single card project in a mobile phone corresponding to an IMEI number, a card in the dual-SIM project corresponding to an IMEI number.
Here is the interface to get the IMEI number and demo code
Api:
Gsmphone.java in Getdeviceid ()
Geminiphone.java Getdeviceid () and Getdeviceidgemini ()

Demo Code:
Import Com.android.internal.telephony.Phone;
Import Com.android.internal.telephony.gemini.GeminiPhone;
Import Com.android.internal.telephony.PhoneFactory;
Phone phone;
Phone = Phonefactory.getdefaultphone ();
String imei= (Geminiphone) Phone.getdeviceid ();

Geminiphone Mgeminiphone;
String imei_sim1 = Mgeminiphone.getdeviceidgemini (phoneconstants.gemini_sim_1);
String imei_sim2 = Mgeminiphone.getdeviceidgemini (phoneconstants.gemini_sim_2);

On the KK version:
Gsmphone.java in Getdeviceid ()
Geminiphone.java where Getdeviceidgemini () is gone, and Getdeviceid () gets the IMEI of the default phone;
So the direct use of Gsmphone.java in the Getdeviceid () method;
Demo Code:
Geminiphone Mgeminiphone;
String Imei_sim1=mgeminiphone.getphonebyid (phoneconstants.gemini_sim_1). Getdeviceid ();
String Imei_sim2=mgeminiphone.getphonebyid (phoneconstants.gemini_sim_2). Getdeviceid ();

2) If you need to obtain the IMEI number in SDK development (third-party apk), use the Getdeviceid () method in Telephonymanager, or Getdeviceid in the Telephonymanagerex (dual Card interface) (int Simid) method.
Demo code (get Defaultphone's IMEI):
Import Android.telephony.TelephonyManager;
String Imei_sim = Telephonymanager.getdeviceid ();

Demo code (Dual Card interface):
Import android.telephony.TelephonyManagerEx;
String imei_sim1 = Telephonymanagerex.getdeviceid (phoneconstants.gemini_sim_1);
String imei_sim2 = Telephonymanagerex.getdeviceid (phoneconstants.gemini_sim_2);

How to get IMEI number in Android

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.