[Android Version]html
Android V2.3 ( GB,GB2)java
Android V4.0, 4.1( ICS, ICS2, JB)android
Android V4.2( JB2,JB3,JB5)app
Android V4.4ide
Android V5.0,5.1函數
[DESCRIPTION]htm
如果須要客製化在通話接通或者斷開時手機震動的行爲,能夠參考如下修改get
[SOLUTION]it
通話接通時:io
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);