android 如何判断去电或来电已经接通

2019-04-13 13:18发布

1、在CallNotifier.java (packagesappsPhonesrccomandroidphone)中定义一个成员变量private Call.State mLastCallState = Call.State.IDLE;
2、在函数onPhoneStateChanged的开始添加代码
Call.State ringCallState = mCM.getFirstActiveRingingCall().getState();
Call.State fgCallState = mCM.getActiveFgCallState();
if ((mLastCallState.isRinging() && ringCallState == Call.State.IDLE) || //MT
   (mLastCallState.isDialing() && fgCallState == Call.State.ACTIVE)) //MO
{
// 进入这里意味着电话已经接通,sergeycao一些操作
}
mLastCallState = ringCallState.isRinging()  ringCallState:fgCallState;