[Android Version]
6573/6575 Android V2.3
6575/6577 Android V4.0
[DESCRIPTION]
当有需要客制化在电话接通时完成一些客制化内容,例如手机震动一声等,可以通过CallState的状态变化来判断是否当时的场景为电话刚接通。
[SOLUTION]
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
{
// 进入这里意味着电话已经接通,可以自己客制化一些操作
}
mLastCallState = ringCallState.isRinging() ? ringCallState:fgCallState;