手机接听或拨打电话时 添加震动

private CallManager mCM;

Phone fgPhone = mCM.getFgPhone();

//这里的Phone是一个系统提供的接口

//public interface Phone extends SprdVideoPhone{
//  enum State {
//       IDLE, RINGING, OFFHOOK;
//   };
//}

//CallManager是

public final class CallManager{}

 if( (fgPhone.getForegroundCall().getState() == Call.State.ACTIVE) &&

(mPreviousCallState != null &&( mPreviousCallState.isDialing() ||

          mPreviousCallState==Call.State.IDLE))){
                callVibrate(); //调用启动震动方法

  }

 private void callVibrate() {
        if(SprdFeatureUtils.SPRD_APP_CALL_VIBRATE_CHANGE_DEFAULT_VALUE == true){
             if (PreferenceManager.getDefaultSharedPreferences(mApplication).getBoolean(KEY_CALL_VIBRATE, false)) {
            Vibrator vibrator = (Vibrator) mApplication.getSystemService(Context.VIBRATOR_SERVICE);
            if (VDBG) log("call vibrate");
            vibrator.vibrate(100);
            }
        }else{
            if (PreferenceManager.getDefaultSharedPreferences(mApplication).getBoolean(KEY_CALL_VIBRATE, true)) {
            Vibrator vibrator = (Vibrator) mApplication.getSystemService(Context.VIBRATOR_SERVICE);
            if (VDBG) log("call vibrate");
            vibrator.vibrate(100);
            }
        }    
    }

涉及到的类:CallNotifier

震动需要权限:<uses-permissionandroid:name="android.permission.VIBRATE"></uses-permission>

你可能感兴趣的:(手机接听或拨打电话时 添加震动)