获取Android的我的电话号码 [英] Get my phone number in android
本文介绍了获取Android的我的电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能在Android的我的电话号码
How can I get my phone number in android
当我使用:
TelephonyManager tMgr =(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();
和使用说明:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
返回null
return Null
为什么?
推荐答案
在<一个href="https://developer.android.com/reference/android/telephony/TelephonyManager.html#getLine1Number%28%29">documentation:
返回线1的电话号码的字符串,例如,该MSISDN对于GSM电话。返回null如果它是不可用的。
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.
这篇关于获取Android的我的电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文