最近,我一直试图实施一种方法来检测是否接听了拨出电话?
我知道这是本论坛的一个老问题。我发现了开发人员提出的所有无用的解决方案。
Tim S.'s answer 使用了一个隐藏的API,该API仅授权系统应用程序受益于PRECISECALL_STATE_ACTIVE
,不能选择具有显示该呼叫是否针对第三方应用程序应答的显式状态。电话管理器提供的第三方应用程序唯一可用的状态是CALL_STATE_RINGING
,CALL_STATE_OFFHOOK
和CALL_STATE_IDLE
,这些状态不能解释我打算做什么。
我的问题是,是否有任何走动,例如隔离来自耳机扬声器的音频源,或远离访问呼叫布局以实时提取呼叫计时器?
代码如下所示:
class Custom_PhoneState_Listener extends PhoneStateListener{
int state;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
//switch to isolate call states
switch(state)
{
case TelephonyManager.CALL_STATE_IDLE:
Log.d("call state:","CALL STATE IDLE");
state=0;
break;
case TelephonyManager.CALL_STATE_RINGING:
Log.d("call state:","CALL STATE RINGING");
state=1;
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d("call state:","CALL STATE OFFHOCK");
state=2;
MyFunction(); //the function should be executed once the call is answered
break;
default: Log.d("call state:","THERE IS NO STATE DETECTED");
}
}`