如何获取当前的SIM卡在实际设备中的手机号码? [英] How to get the mobile number of current sim card in real device?
问题描述
我不得不作出其示出了没有联系的是在细胞中所使用的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();
的<一个href="http://developer.android.com/intl/fr/reference/android/telephony/TelephonyManager.html#getLine1Number%28%29">documentation为 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.
你需要给你的应用程序的permission加入使这个查询以下到您的清单:
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()
获得 TelephonyManager
作为的that是一个私人未公开的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卡在实际设备中的手机号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!