Reputation: 2403
I am using the below method to get the phone number of my device
private void getMyNumber()
{
// read_phone_State permission is specified
String ph_num ="";
TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
ph_num = telephonyManager.getLine1Number(); // returning null
ph_num = telephonyManager.getSimSerialNumber(); // returning sim serial number
ph_num = telephonyManager.getSubscriberId(); // returning id
ph_num = telephonyManager.getVoiceMailNumber(); // returning null
}
Any ideas ... how to get the phone number
Upvotes: 1
Views: 515
Reputation: 23171
There is no 100% reliable way to get the phone number since whether or not the telephonyManager has access to it is dependent on the provider and how they encode the data on the SIM (for GSM phones, at least). If you want the phone number to uniquely identify the phone, use telephonyManager.getDeviceId()
otherwise you may have to prompt the user for it.
Upvotes: 1