其他分享
首页 > 其他分享> > 在Android中从TelephonyManager检索Line1号码

在Android中从TelephonyManager检索Line1号码

作者:互联网

TelephonyManager manager1 = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String strMobile1 = manager1.getLine1Number();  

这是我的代码,用于获取手机号码,但无法正常工作.我也已在清单文件中获得必要的许可

解决方法:

我们的项目中有同样的问题.结论是它取决于SIM卡.

我们发生了什么事:

Galaxy S with AT&T SIM card: can read phone number, Settings shows number
Same Galaxy with an European SIM card: cannot read the number and "unknown" in Settings (cell phone was perfectly functional, just couldn't read the number)
This has been reported in other forums as well.

In the end we decided to ask the user for the phone number. A bit more involved, actually: if( "SIM card present" && "cannot read the cell number") "ask user"; . Otherwise we will keep bugging the user that doesn't a SIM card in the first place.

getLine1Number() only get the number stored on the sim card..a lot of operators don't write there the sim number..on some phones (nokia, blackberry, some olds android, iphone) you can set your own mobile number and the phone will store it on the sim card, at that point getLine1Number() will return the phone number

标签:telephonymanager,android
来源: https://codeday.me/bug/20191013/1909686.html