Android Call Flip Mute implementation source

Source: Internet
Author: User

1. Add the implementation file:

Alps\packages\apps\incallui\src\com\android\incallui\sensorfunctionserviceincall.java

/* Copyright (C) The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License") ; * You are not a use this file except in compliance with the License. * Obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * unless required by appli Cable law or agreed into writing, software * Distributed under the License is distributed on a "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.ad  Dpackage 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 mreversed                  OWNFLG = 0; } else if (Event.values[sensormanager.data_z] <= critical_down_angle &&mreversedownflg ==0) {//                Screen down next mreversedownflg = 1;                      } if (Mreversedownflg ==1) {//screen reverse from-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);p reviousmutemode = 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. Add the call response location:

Alps\packages\apps\incallui\src\com\android\incallui\incallactivity.java

    @Override    protected void OnStart () {        log.d (this, "OnStart () ...");        Super.onstart ();        Setting activity should is 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    }


Android Call Flip Mute implementation source

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.