简体   繁体   English

如何获取设备的电话号码

[英]How to get the telephone number of the device

I want to retrieve telephone number of the current Device. 我想检索当前设备的电话号码。 Now I cannot get the telephone number. 现在我无法获得电话号码。 I have added READ_PHONE_STATE permission in manifest. 我在清单中添加了READ_PHONE_STATE权限。 Here is my code 这是我的代码

TelephonyManager tMgr = (TelephonyManager) this.getSystemService(Context.
String mPhoneNumber = tMgr.getLine1Number();  

Code : 代码:

 TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
 String mPhoneNumber = tMgr.getLine1Number();

Required Permission: 所需权限:

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

refer to link : Programmatically obtain the phone number of the Android phone 参考链接:以编程方式获取Android手机的电话号码

You need to have stored the phone number on the SIM card, and there´s no other way to get your "own number". 您需要将电话号码存储在SIM卡上,没有其他方法可以获取您的“自己的号码”。

Check this link 检查链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM