I am trying to read the phone number of the device using the following code. When phone number is not available I read the subcriber id. It works in some phones and throws NULL pointer exception in some devices. The device log shows I am getting NULL pointer exception in the following line
if(MyPhoneNumber.equals(""))
Please let me know how to make it work in all devices.
TelephonyManager tMgr =(TelephonyManager)ShowMyLocation.this.getSystemService(Context.TELEPHONY_SERVICE);
String MyPhoneNumber = tMgr.getLine1Number();
if(MyPhoneNumber.equals(""))
MyPhoneNumber = tMgr.getSubscriberId();
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…