在Android中获取我的电话号码(Get my phone number in android)
如何在Android中获取我的电话号码?
当我使用:
TelephonyManager tMgr =(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); String mPhoneNumber = tMgr.getLine1Number();并使用:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />返回空
为什么?
How can I get my phone number in Android? When I use:
TelephonyManager tMgr =(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); String mPhoneNumber = tMgr.getLine1Number();and use:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />it returns null, why?
最满意答案
从文档 :
返回第1行的电话号码字符串,例如GSM手机的MSISDN。 如果不可用,返回null。
所以你做了一切正确,但没有电话号码存储。
如果你为null ,你可以显示一些东西,让用户输入他/她自己的电话号码。
From the documentation:
Returns the phone number string for line 1, for example, the MSISDN for a GSM phone. Return null if it is unavailable.
So you have done everything right, but there is no phone number stored.
If you get null, you could display something to get the user to input the phone number on his/her own.
更多推荐
发布评论