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鏈接