Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getLine1Number() is not working [duplicate]

Tags:

android

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?

like image 673
Khalid Taha Avatar asked Nov 06 '12 12:11

Khalid Taha


1 Answers

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.

like image 143
Chintan Khetiya Avatar answered Oct 04 '22 12:10

Chintan Khetiya