How to obtain the IMEI number in android

Source: Internet
Author: User

How to obtain the IMEI number in android
1) within the Telephony Framework, you can directly use interfaces provided by GSM phone or GeminiPhone.
Versions earlier than KK:
IMEI (International Mobile Equipment Identity) is an International Mobile device Identity code. In the single-Card Project, a Mobile phone corresponds to an IMEI number, and in the dual-Card Project, a card corresponds to an IMEI number.
The following is the interface and demo code for obtaining the IMEI number.
API:
GetDeviceId () in GSMPhone. java ()
GetDeviceId () and getDeviceIdGemini () in GeminiPhone. java ()

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 );

KK version:
GetDeviceId () in GSMPhone. java ()
In GeminiPhone. java, getDeviceIdGemini () is no longer available, while getDeviceId () obtains the IMEI of the default phone;
Therefore, use the getDeviceId () method in GSMPhone. java;
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) to obtain the IMEI number In SDK Development (third-party APK), use the getDeviceId () method in TelephonyManager or the getDeviceId (int simId) method in TelephonyManagerEx (dual-card interface.
Demo code (get the IMEI of DefaultPhone ):
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 );

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.