检索电话号码,最好的方法? [英] best way to retrieve phone number?
本文介绍了检索电话号码,最好的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够获得SIM卡的电话号码,目前我一直在用:
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.
反正是有得到正确的电话号码的100%的时间,而不要求用户手动输入?
is there anyway of getting the correct phone number 100% of the time, without asking the user to manually enter it?
推荐答案
使用此。
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
String imei = tm.getDeviceId();
String phone = tm.getLine1Number();
但它不是如非手机设备总是可靠的。您还需要添加权限android.permission.READ_PHONE_STATE。
but it's not always reliable on for example non phone device. You will also need to add permission "android.permission.READ_PHONE_STATE".
这篇关于检索电话号码,最好的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文