I want to get the telephone Number. I used this sample code..
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE)开发者_运维技巧;
String strphonenumber = tm.getLine1Number();
And I used the permission- READ_PHONE_STATE.
But its returning null.
You will only be able to get the Number from a CDMA device.
public String returnNumber() {
String number = null;
String service = Context.TELEPHONY_SERVICE;
TelephonyManager tel_manager = (TelephonyManager) getSystemService(service);
int device_type = tel_manager.getPhoneType();
switch (device_type) {
case (TelephonyManager.PHONE_TYPE_CDMA):
number = tel_manager.getLine1Number();
break;
default:
//return something else
number = "no number";
break;
}
return number;
}
精彩评论