0
我想检索当前设备的电话号码。现在我无法获得电话号码。我已在清单中添加了READ_PHONE_STATE权限。这是我的代码如何获取设备的电话号码
TelephonyManager tMgr = (TelephonyManager) this.getSystemService(Context.
String mPhoneNumber = tMgr.getLine1Number();
我想检索当前设备的电话号码。现在我无法获得电话号码。我已在清单中添加了READ_PHONE_STATE权限。这是我的代码如何获取设备的电话号码
TelephonyManager tMgr = (TelephonyManager) this.getSystemService(Context.
String mPhoneNumber = tMgr.getLine1Number();
代码:
TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();
所需的权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
参考链接:Programmatically obtain the phone number of the Android phone
您需要在SIM卡上存储电话号码,并且没有其他方法可以获得您的“自己的号码”。
检查this链接