基于这三种状态:
TelephonyManager.CALL_STATE_IDLE
TelephonyManager.CALL_STATE_OFFHOOK
TelephonyManager.CALL_STATE_RINGING:
是否可以判断是否有来电?
具体来说,如果有来电,
答案 0 :(得分:1)
你应该使用你自己的类扩展PhoneStateListener来处理调用状态的变化:
CallStateListener callListener= new CallStateListener ();
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
然后,您自己的类的以下代码:
public class CallStateListener extends PhoneStateListener {
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
Log.d(CallStateListener.class.getSimpleName(), "CALL_STATE_IDLE");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d(CallStateListener.class.getSimpleName(), "CALL_STATE_OFFHOOK");
break;
case TelephonyManager.CALL_STATE_RINGING:
Log.d(CallStateListener.class.getSimpleName(), "CALL_STATE_RINGING");
break;
}
}
}