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

1、在CallNotifier.java (packages\apps\Phone\src\com\android\phone)中定义一个成员变量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;

你可能感兴趣的:(android)