5

I want to retrieve the own mobile number and the IMEI.

How do I get this information from the Android phone?

Janusz
  • 187,060
  • 113
  • 301
  • 369
Maidul
  • 1,289
  • 16
  • 30

2 Answers2

17

use

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
String imei = tm.getDeviceId();
String phone = tm.getLine1Number();

but its not always reliable on for example non phone device.

and you should also add this following permission to your AndroidManifest.xml file

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Arsh Kaushal
  • 521
  • 1
  • 5
  • 18
mkso
  • 3,178
  • 4
  • 27
  • 35
  • 1
    Not all devices detect the phone number, at least in my LG optimus black I have to put it in manually (and not a lot of users do this I guess). – Paulina D. Oct 25 '11 at 21:07
2

getLine1Number();

this method returns the phone number string for line 1,
i.e the MSISDN for a GSM phone. Return null if it is unavailable.

but what about CDMA phone?

Note : this method works only for few cell phone not for all devices

.

Arsh Kaushal
  • 521
  • 1
  • 5
  • 18
Jayesh
  • 3,661
  • 10
  • 46
  • 76