获取设备的电话号码

发布于 2024-12-22 10:34:54 字数 369 浏览 3 评论 0原文

我正在制作一个应用程序,其中我必须获取 GSM 设备的手机号码,我使用以下代码在 TextView 中显示电话号码,但一切都是徒劳的。谁能帮我做到这一点。

TelephonyManager mTelephonyMgr;
    mTelephonyMgr = (TelephonyManager)
        getSystemService(Context.TELEPHONY_SERVICE);

    String number = mTelephonyMgr.getLine1Number();

    Phoneno=(TextView)findViewById(R.id.Phoneno);


    Phoneno.setText(number);

I am making an app in which I have to get the mobile number of the GSM device and I used the following code to show to phone no in a TextView, but all in vain. Can anyone help me do this.

TelephonyManager mTelephonyMgr;
    mTelephonyMgr = (TelephonyManager)
        getSystemService(Context.TELEPHONY_SERVICE);

    String number = mTelephonyMgr.getLine1Number();

    Phoneno=(TextView)findViewById(R.id.Phoneno);


    Phoneno.setText(number);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

神魇的王 2024-12-29 10:34:54

确保您在清单中需要权限READ_PHONE_STATE

希望这个会帮助你

make sure you Requires permission READ_PHONE_STATE in manifest

Hope This will help you

冷月断魂刀 2024-12-29 10:34:54

查看这个例子,它将帮助您找出问题所在。

Check this example, it will help you to find out the issue.

我很OK 2024-12-29 10:34:54

TelephonyManager.getLine1Number() 是迄今为止唯一可用的解决方案。实际上 sim 不包含有关号码的信息。它仅由网络传递。这也是 sim 相关的。对于某些设备,它 (TelephonyManager.getLine1Number()) 可以工作.对于某些人来说可能不是。

TelephonyManager.getLine1Number() is the only solution available till now.Actually sim does not contains info about the number .It is delivered by the network only.Also this is sim dependent .For some device it (TelephonyManager.getLine1Number()) will work.For some it may not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文