gpt4 book ai didi

Android:广播接收器中的电话状态

转载 作者:行者123 更新时间:2023-11-29 14:06:18 25 4
gpt4 key购买 nike

我使用广播接收器捕捉电话状态变化。当状态第一次改变时它工作正常(对于 State_OffHook),但在调用结束时不要使用react。这是我的代码:

String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);                     
if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) {working fine}
else if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) {doesn't react}

最佳答案

当你没有来电时,你处于IDLE状态,当你接到电话时,它进入OFFHOOK状态当您的通话结束时,它会再次进入 IDLE 状态

获取更多信息引用这个

How to know whether I am in a call on Android?

编辑:

@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);

switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
// Toast.makeText(context, "Idle", Toast.LENGTH_LONG).show();
if(UDF.phoneState != TelephonyManager.CALL_STATE_IDLE) {
//Here you are came from offhook because value of UDF.phoneState != TelephonyManager.CALL_STATE_IDLE
//IDLE is calls many times so you have to keep track by a static variable like UDF.phoneState
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//Toast.makeText(context, "Idle", Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_RINGING:
//Toast.makeText(context, "Idle", Toast.LENGTH_LONG).show();
endCallIfBlocked(incomingNumber);
break;

default:
break;
}
UDF.phoneState = state;
}

关于Android:广播接收器中的电话状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6729072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com