GetLine1Number () does not work

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 be Toast "Length is zero." When I print a number, it doesn't print anything. Can someone give me a solution?

+7
source share
2 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 otherwie applicable show it .

+4
source

Buddy, this happens to me, in the end I will find out this decision

+1
source

All Articles