Reputation: 523
i need to be able to get the SIM's phone number, currently i have been using:
telephonyManager = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
tmPhone = telephonyManager.getLine1Number();
but this method doesnt always return a result/the correct result.
is there anyway of getting the correct phone number 100% of the time, without asking the user to manually enter it?
Upvotes: 2
Views: 454
Reputation: 1287
Use This.
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
String imei = tm.getDeviceId();
String phone = tm.getLine1Number();
but it's not always reliable on for example non phone device. You will also need to add permission "android.permission.READ_PHONE_STATE".
Upvotes: 1