1.添加实现文件:

alps\packages\apps\InCallUI\src\com\android\incallui\SensorFunctionServiceIncall.java

/* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License *///cbk.flip.func.addpackage com.android.incallui;import android.app.Service;  import android.content.Context;  import android.content.Intent;  import android.hardware.Sensor;  import android.hardware.SensorEvent;  import android.hardware.SensorEventListener;  import android.hardware.SensorManager;  import android.os.IBinder;  import android.os.PowerManager; import android.media.AudioManager;import android.util.Log;import android.content.BroadcastReceiver;public class SensorFunctionServiceIncall extends Service {            private static final String LOG_TAG = "InCallActivity/SensorFunctionServiceIncall";      private static final float CRITICAL_DOWN_ANGLE = -5.0f;      private static final float CRITICAL_UP_ANGLE = 5.0f;      private static final int Z_ORATIATION = 2;            private SensorManager mSensorManager;      private Sensor mGsensor;      private SensorEventListener mGsensorListener;      private PowerManager pm;      private int mReverseDownFlg= -1;     private int previousMuteMode = -1;    private boolean mActFlag=false;       @Override      public void onCreate() {          super.onCreate();          pm = (PowerManager) getSystemService(Context.POWER_SERVICE);                    mSensorManager= (SensorManager) getSystemService(SENSOR_SERVICE);             mGsensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);//TYPE_GRAVITY);         Log.d(LOG_TAG, "onCreate()...  this = " + this);        mGsensorListener = new SensorEventListener() {                @Override              public void onAccuracyChanged(Sensor sensor, int accuracy) {              }                @Override              public void onSensorChanged(SensorEvent event) {                  //Log.d(LOG_TAG, "onSensorChanged()...  event = " + event);                Log.d(LOG_TAG, "onSensorChanged()...  event.values[SensorManager.DATA_Z] = " + event.values[SensorManager.DATA_Z]);                if(event.values[SensorManager.DATA_Z] >= CRITICAL_UP_ANGLE ){ //screen up  first                    mReverseDownFlg = 0;                  } else if(event.values[SensorManager.DATA_Z] <= CRITICAL_DOWN_ANGLE                 &&mReverseDownFlg ==0){  //screen down next                      mReverseDownFlg = 1;                }                  if(mReverseDownFlg ==1){ //screen reverse from up to down                    if(mActFlag ==false){                      mActFlag = true;  /*                    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);                    audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);*/AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);if (previousMuteMode == -1){previousMuteMode = am.getRingerMode();am.setRingerMode(0);}am.setRingerMode(previousMuteMode);previousMuteMode = -1;                    Log.d(LOG_TAG, "onSensorChanged()...  mActFlag = " + mActFlag);                    }                }            }           };                           mSensorManager.registerListener(mGsensorListener, mGsensor, SensorManager.SENSOR_DELAY_GAME);      }            @Override      public IBinder onBind(Intent arg0) {          return null;      }  }  //cbk.flip.func.add


2.添加来电响应位置:

alps\packages\apps\InCallUI\src\com\android\incallui\InCallActivity.java

    @Override    protected void onStart() {        Log.d(this, "onStart()...");        super.onStart();        // setting activity should be last thing in setup process        InCallPresenter.getInstance().setActivity(this);//cbk.flip.func.add      if (FeatureOption.FLIP_FUNC_SUPPORT) {        final boolean gFlipMuteEnabled = Settings.System.getInt(getContentResolver(),                Settings.System.FLIP_MUTE_INCOMMING_CALL, 0) != 0;      if (gFlipMuteEnabled) {final Intent i = new Intent(this, SensorFunctionServiceIncall.class);        i.setAction("com.android.services.telephony.common.ISensorFunctionServiceIncall");this.startService(i);//startService(getApplicationContext(), SensorFunctionServiceIncall.class);      }      }//cbk.flip.func.add    }


更多相关文章

  1. Android简单文件浏览器源代码
  2. android播放音频文件(MediaPlayer)和录音(MediaRecorder)--播放
  3. 文件操作与SDCard读写访问
  4. Android Studio 小技巧(1):如何导入AAR文件
  5. android 开发-文件存储之读写sdcard
  6. 怎么在android的XML文件里加入凝视
  7. android下大文件分割上传
  8. android 打开预览不同类型文件

随机推荐

  1. ndk下载地址
  2. Android(安卓)IPC Compared with Java Na
  3. Could not find com.android.tools.build
  4. android-Java中实现删除文件 - 随心
  5. Android(安卓)多线程下载
  6. Xamarin.Android(安卓)4.10.01068 & Xama
  7. Android(安卓)doc打开太慢
  8. android actionbar 主题
  9. Android(安卓)Notification通知详解
  10. JAVA-阴历阳历转换