在Android中获取我的电话号码(Get my phone number in android)

编程入门 行业动态 更新时间:2024-10-23 04:46:31
在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.

更多推荐

本文发布于:2023-07-23 18:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235692.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电话号码   Android   phone   android   number

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!