TelephonyManager.getLine1Number()失败?TelephonyManager、getLine1Number

2023-09-12 00:03:31 作者:繁花灬不弃

我想要得到的Andr​​oid设备的电话号码。我用这个code:

I want to get phone number of android device. I use this code:

TelephonyManager tm = (TelephonyManager)this.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE); 
String phoneNumber=  tm.getLine1Number();

在我的手机(HTC野火)我不能得到的电话号码 - 我得到的是空字符串。如果我运行在emulatur code,电话号码通常显示。

On my phone (HTC Wildfire) I can not get phone number - all I get is empty string. If I run code on emulatur, phone number is normally showed.

如果我去设置=>关于手机=>手机身份 - >电话号码,电话号码为未知。

If I go to Settings=>About phone=>Phone identity->Phone number, phone number is "Unknown".

问题出在哪里?有什么问题我的SIM卡?

Where is the problem? Is something wrong with my SIM?

推荐答案

我们有我们的项目同样的问题。得出的结论是,这取决于SIM卡上。

We had the same problem in our project. The conclusion was that it depends on the SIM card.

发生了什么事我们:

的Galaxy S与AT& T公司的SIM卡:可以读取电话号码,设置显示号码 在同一星系与欧洲SIM卡:不能读取设置的数量,未知(手机是完美的功能,只是无法阅读次数)

这已经报告在其他论坛也。

This has been reported in other forums as well.

在最后我们决定索要电话号码的用户。更多地参与了一下,居然:如果(SIM卡present&放大器;&放大器;不能读取手机号码),询问用户; 。否则,我们将继续窃听,这并不SIM卡摆在首位用户。

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.