Reputation:
I am making an app in which I have to get the mobile number of the GSM device and I used the following code to show to phone no in a TextView, but all in vain. Can anyone help me do this.
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
String number = mTelephonyMgr.getLine1Number();
Phoneno=(TextView)findViewById(R.id.Phoneno);
Phoneno.setText(number);
Upvotes: 2
Views: 20276
Reputation: 166
TelephonyManager.getLine1Number() is the only solution available till now.Actually sim does not contains info about the number .It is delivered by the network only.Also this is sim dependent .For some device it (TelephonyManager.getLine1Number()) will work.For some it may not.
Upvotes: 0
Reputation: 22066
make sure you Requires permission READ_PHONE_STATE in manifest
Hope This will help you
Upvotes: 2