微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 手机设计讨论 > MTK手机平台交流 > 如何在通话接通和断开时震动

如何在通话接通和断开时震动

时间:10-02 整理:3721RD 点击:
[android Version]
Android V2.3 (GB,GB2)
Android V4.0, 4.1(ICS,ICS2,JB)
Android V4.2(JB2,JB3,JB5)
[DESCRIPTION]
若是需要客制化在通话接通或者断开时手机震动的行为,可以参考以下修改
[SOLUTION]
通话接通时:
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_SER
VICE);
}
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;
通话挂断后:
在CallNotifier.Java (alps\packages\apps\phone\src\com\android\phone)的
onDisconnect ()中
Phone.State state = mCM.getState() ;后添加如下Code
if (mVibrator == null){
mVibrator = (Vibrator)
mApplication.getApplicationContext().getSystemService(Context.VIBRATOR_SER
VICE);
}
final int CALL_DISC_VIBRATE_TIME = 300; // msec
mVibrator.vibrate(CALL_DISC_VIBRATE_TIME);

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top