8

I want to get The SIM phone number using android but when I get The number the length is zero! here is the code:

TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(getApplicationContext().TELEPHONY_SERVICE);
String s=mTelephonyMgr.getLine1Number();
Toast.makeText(getBaseContext(), "The length is "+s.length(), Toast.LENGTH_LONG).show();

but it will Toast " The length is zero". When I print the number it will print nothing. Can anyone give me a solution?

Khalid Taha
  • 3,183
  • 5
  • 27
  • 43

2 Answers2

5

Get SIM Number

 TelephonyManager telemamanger = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String getSimSerialNumber = telemamanger.getSimSerialNumber();

Get Phone Number

TelephonyManager tMgr =(TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
  mPhoneNumber = tMgr.getLine1Number();

This Will Show you if applicable otherwie show this.

Community
  • 1
  • 1
Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
1

Buddy it happens to me also , in the end i come to know this solution

Community
  • 1
  • 1
Ronak Mehta
  • 5,971
  • 5
  • 42
  • 69
  • I've also seen this issue, it is highly SIM and device dependant. You can't guarantee that Android will be able to provide you the device phone number. – Guykun Nov 06 '12 at 14:00