[Android Version]
Android V2.3 ( GB,GB2)
Android V4.0, 4.1( ICS, ICS2, JB)
Android V4.2( JB2,JB3,JB5)
Android V4.4
Android V5.0,5.1
[DESCRIPTION]
若是需要客制化在通话接通或者断开时手机震动的行为,可以参考以下修改
[SOLUTION]
通话接通时:
Android V4.4之前版本:
1 在packages\apps\phone\src\com\android\phone\CallNotifier.java开头处添加private Vibrator mVibrator;
2 在packages\apps\phone\src\com\android\phone\CallNotifier.java函数onPhoneStateChanged开头处添加
if (mVibrator == null){
mVibrator = (Vibrator)
mApplication.getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
}
3 在packages\apps\phone\src\com\android\phone\CallNotifier.java中添加一个成员变量
Call.State mLastCallState = Call.State.IDLE;
然后在函数onPhoneStateChanged中的语句Phone fgPhone = mCM.getFgPhone();后添加以下代码
Call.State ringCallState =
mCM.getRingingPhone().getRingingCall().getState();
Call.State fgCallState = mCM.getActiveFgCallState();
if ((ringCallState==Call.State.IDLE && mLastCallState.isRinging()) ||//MT
(fgCallState==Call.State.ACTIVE && mLastCallState.isDialing()))//MO
{
//here means that call is connected
final int MO_CALL_VIBRATE_TIME = 300; // msec
mVibrator.vibrate(MO_CALL_VIBRATE_TIME);
}
mLastCallState = ringCallState.isRinging() ? ringCallState:fgCallState;
mtkAndroid V4.4及之后版本:
已有此功能。
通话挂断后:
在CallNotifier.java onDisconnect ()中
Phone.State state = mCM.getState() ;后添加如下Code
if (mVibrator == null){
mVibrator = (Vibrator)
mApplication.getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
}
final int CALL_DISC_VIBRATE_TIME = 300; // msec
mVibrator.vibrate(CALL_DISC_VIBRATE_TIME);
转载于:https://blog.51cto.com/132588761/1965378