我使用Intent.ACTION_SCREEN_OFF
和Intent.ACTION_SCREEN_ON
创建自己的LockScreen。但是当我打电话时它仍然有效。我引用了这段代码,但它没有用。
StateListener phoneStateListener = new StateListener();
TelephonyManager telephonymanager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
telephonymanager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}catch(Exception e){ }
}
class StateListener extends PhoneStateListener{
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch(state){
case TelephonyManager.CALL_STATE_RINGING:
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
System.out.println("call Activity off hook");
// Finish lock screen activity
finish();
break;
case TelephonyManager.CALL_STATE_IDLE:
break;
}
}
};