我有以下代码,并且我已经阅读了当两方之间的电话连接并且对方实际上可以看到您正在呼叫并接听您的电话时,振铃状态处于活动状态。空闲状态是呼叫断开时,OFF_HOOK 状态是您按下按钮拨号的时刻。我进入 OFF_HOOK 和空闲状态但无法进入振铃状态。可能是什么问题?。任何帮助将不胜感激。
public void onReceive(final Context context, Intent intent) {
TelephonyManager Tm=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
Tm.listen(new PhoneStateListener(){
public void onCallStateChanged(int state,String number) {
super.onCallStateChanged(state, number);
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
//when Idle i.e no call
Toast.makeText(context, "Phone state Idle", 1).show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//when Off hook i.e in call
//Make intent and start your service here
Toast.makeText(context, "Phone state Off hook", 1).show();
break;
case TelephonyManager.CALL_STATE_RINGING:
Toast.makeText(context, "Phone state Ringing", 1).show();
break;
default:
break;
}
}
},PhoneStateListener.LISTEN_CALL_STATE);