简体   繁体   English

Android-在通话中以编程方式禁用接近传感器

[英]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). 我正在开发一个可以在通话中运行的android应用程序,在这种情况下,用户需要屏幕(他/她与耳机通话)。

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: ================================================== ====================编辑:根据Mike Armstrong的回应,我尝试了此尝试,但未成功:

In activity onCreate(): 在活动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. 如果您是有意拨打电话,那么您将默认使用android手机应用程序,这绝对不会超出您的应用程序范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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