5

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

How do I get this information from the Android phone?

Janusz
  • 182,484
  • 112
  • 300
  • 368
Maidul
  • 1,279
  • 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
  • 17
mkso
  • 3,148
  • 4
  • 26
  • 34
  • 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
  • 17
Jayesh
  • 3,541
  • 8
  • 42
  • 75