我有下面的代碼,以獲得我的應用程序的手機狀態:的Android PhoneStateListener錯誤狀態
private PhoneStateListener phoneListener = new PhoneStateListener(){
public void onCallStateChanged(int state,String incomingNumber){
switch(state){
case TelephonyManager.CALL_STATE_IDLE:
Log.i(TAG, "IDLE");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.i(TAG, "OFFHOOK");
break;
case TelephonyManager.CALL_STATE_RINGING:
Log.i(TAG, "RINGING");
break;
}
}
};
所有工作在兩個仿真器(在Android 6.0和Android 4.4)的罰款。但我真正的設備上(Android 4.4系統,Oukitel原)我已經得到了以下輸出,同時振鈴:
RINGING
IDLE //in real I'm still ringing here.
IDLE //real stop ringing
是否有任何狡猾的功能,或者它只是一個錯誤的固件?不幸的是,我的搜索沒有任何結果。
UPD 它適用於某些設備,對於其他設備,它的工作方式如上所述。
一些更多的細節。我在我的服務的onStartCommand中設置了此偵聽器。如果TelephonyManager.EXTRA_STATE_RINGING得到了注意,那麼它將從廣播接收器開始。
UPD2 嗯,我找到了一個解決方案。廣播接收器工作正常,所以我剛切換到Receiver通知。但是真的很有趣,PhoneStateListener出了什麼問題。如果有人有任何想法,請告訴我。
請勿張貼鏈接只回答他們,因爲他們可能會隨時間而死亡。相反,討論OP可能做錯了什麼。 – Shaishav
好的,文章中的代碼工作正常,但是...我沒有看到與我的代碼有任何區別。 – Tamplier