-1

I'm having troubles getting the phone number in certain phones with EURO operators, I try with TelephonyManager using getLine1Number() for get the SIM number, that work fine but in order to get a GSM phone number the method return a empty string. So, the question is, how can I get that info without getLine1Number() method?

Any way is valid, just I need take that information and send SMS to user or register using a phone number as username.

1 Answers1

0

In some countries, SIM does not store phone numbers. If you want an unique user number, you can use subscriber ID:

TelephonyManager telMan = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = "00";
try {
    phoneNumber =telMan.getLine1Number();
} catch(NullPointerException ex) {
    ex.printStackTrace();
}
if(phoneNumber.equals("")){
    phoneNumber = telMan.getSubscriberId();
}
Kuvalya
  • 1,094
  • 1
  • 15
  • 26