如何在真实设备中获取当前SIM卡的手机号码?

编程入门 行业动态 更新时间:2024-10-24 15:25:34
本文介绍了如何在真实设备中获取当前SIM卡的手机号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我必须创建一个显示该单元中正在使用的SIM卡的联系人号码的应用程序.为此,我需要使用TelephonyManager类.我可以获取有关其用法的详细信息吗?

I have to make an application which shows the contact no of the SIM card that is being used in the cell. For that I need to use TelephonyManager class. Can I get details on its usage?

推荐答案

您可以使用 TelephonyManager 为此:

You can use the TelephonyManager to do this:

TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); String number = tm.getLine1Number();

getLine1Number()的文档

The documentation for getLine1Number() says this method will return null if the number is "unavailable", but it does not say when the number might be unavailable.

您需要授予您的应用程序通过在清单中添加以下内容来进行此查询:

You'll need to give your application permission to make this query by adding the following to your Manifest:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

(您不应该使用TelephonyManager.getDefault()作为这是一个未公开的私有API调用,将来可能会更改.)

(You shouldn't use TelephonyManager.getDefault() to get the TelephonyManager as that is a private undocumented API call and may change in future.)

更多推荐

如何在真实设备中获取当前SIM卡的手机号码?

本文发布于:2023-11-28 06:44:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641345.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:手机号码   真实   设备   如何在   SIM

发布评论

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

>www.elefans.com

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