Android 来电翻转静音实现源码

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 * * * * 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;@Overridepublic 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() {@Overridepublic void onAccuracyChanged(Sensor sensor, int accuracy) {}@Overridepublic 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 firstmReverseDownFlg = 0;} else if(event.values[SensorManager.DATA_Z] <= CRITICAL_DOWN_ANGLE&&mReverseDownFlg ==0){ //screen down nextmReverseDownFlg = 1;}if(mReverseDownFlg ==1){ //screen reverse from up to downif(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);}@Overridepublic IBinder onBind(Intent arg0) {return null;}} //cbk.flip.func.add

2.添加来电响应位置:

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

@Overrideprotected void onStart() {Log.d(this, "onStart()…");super.onStart();// setting activity should be last thing in setup processInCallPresenter.getInstance().setActivity(this);//cbk.flip.func.addif (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}

,快乐要有悲伤作陪,雨过应该就有天晴。

Android 来电翻转静音实现源码

相关文章:

你感兴趣的文章:

标签云: