开发者

best way to retrieve phone number?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜