我必须创建一个显示该单元中正在使用的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()的文档表示如果数字不可用",则此方法将返回null,但没有说明数字何时不可用.
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卡的手机号码?
发布评论