国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php开源 > 综合技术 > Android 来电翻转静音实现源码

Android 来电翻转静音实现源码

来源:程序员人生   发布时间:2015-08-19 08:28:17 阅读次数:2975次

1.添加实现文件:

alpspackagesappsInCallUIsrccomandroidincalluiSensorFunctionServiceIncall.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⑵.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.add package 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 = ⑸.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= ⑴; private int previousMuteMode = ⑴; 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 == ⑴) { previousMuteMode = am.getRingerMode(); am.setRingerMode(0); } am.setRingerMode(previousMuteMode); previousMuteMode = ⑴; 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.添加来电响应位置:

alpspackagesappsInCallUIsrccomandroidincalluiInCallActivity.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 }


生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生