开发者

best way to retrieve phone number?

开发者 https://www.devze.com 2023-04-01 00:53 出处:网络
i need to be able to get the SIM\'s phone number, currently i have开发者_开发技巧 been using: telephonyManager = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);

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?


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".

0

精彩评论

暂无评论...
验证码 换一张
取 消