简体   繁体   中英

Android - disable proximity sensor programmatically within a call

I am developing an android application which can run with an active call, in this case the user needs the screen (he/she talks with a headsets).

The problem is the proximity sensor, if the user taps it the screen goes black, is there any way, from the code, programmatically, without rooting, in which I can disable this function?

Thanks.

======================================================================= EDIT: From Mike Armstrong response, I tried this without success:

In activity onCreate():

// Disable proximity sensor.
SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
sensorManager.registerListener(getSensorListener(), sensor, SensorManager.SENSOR_DELAY_NORMAL);

Listener:

private SensorEventListener getSensorListener(){

    return new SensorEventListener() {
        @Override
        public void onSensorChanged(SensorEvent event) {
            // nothing.
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            // nothing.
        }
    };
}

Great question! Checkout this...

http://developer.android.com/guide/topics/sensors/sensors_position.html

Simply handling a listener to the proximity sensor should override it during your call, as long as you're not making a call with an intent. If you're making a call with an intent then you'll default to the android phone app and that will most definitely be out of scope in terms of your app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM