2015-04-01 75 views
0

我想檢索當前設備的電話號碼。現在我無法獲得電話號碼。我已在清單中添加了READ_PHONE_STATE權限。這是我的代碼如何獲取設備的電話號碼

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

回答

2

代碼:

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

0

您需要在SIM卡上存儲電話號碼,並且沒有其他方法可以獲得您的「自己的號碼」。

檢查this鏈接

相關問題