![](/img/trans.png)
[英]Phone number is set to null at the time of OFFHOOK state of TelephonyManager
[英]TelephonyManager unable to return phone number in android
我正在實施一個支付應用程序。 所以為了聯系驗證,我必須找到聯系電話。 此外,我正在從 sim 發送一條短信,以便在服務器上進行交叉驗證。 我試過了
> TelephonyManager tm =
> (TelephonyManager)this.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
> String phoneNumber= tm.getLine1Number();
但我無法獲得聯系電話。 我還實現了廣播接收器來檢查發送或發送的天氣短信。 那么有沒有辦法獲取聯系電話呢?
您是否在清單中定義了此權限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
也使用getActivity().getApplicationContext();
代替this.getApplicationContext()
如果您使用片段
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.