Search code examples
androidtelephonymanager

Get mobile Number on GSM Mobile using android code


I am using following android code to get mobile number and it's working on android emulators only:

TelephonyManager tm =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String number = tm.getLine1Number();

But when I tested it in real device (Samsung Galaxy Chat B5330) it gives nothing (Empty String)

Please help with some code snippet.


Solution

  • For GSM, the phone number is on the SIM card, and some carriers just don't put it on the card, and then the phone does not know what it is, but in this case you should get an empry string rather than a null

    if the carrier stores the number on your SIM, go to Settings -> About Phone -> Status -> My phone Number. If it displays unknown there, then your number is not stored on the SIM.

    enter image description here

    get IMEI use:

    TelephonyManager tm =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    imei_no = tm.getDeviceId();