How to change Android proximity sensor sensitivity?

假如想象 提交于 2019-12-06 16:55:37

Just "implements SensorEventListener" and follow the code :

public void onCallStateChanged(int state, String incomingNumber) {
        switch (state) {
        case TelephonyManager.CALL_STATE_IDLE:
            System.out.println("My Call IDLE");
            CallState = false;
            StartAudioSpeacker();
            System.out.println("Is phone speaker : "+ audioManager.isSpeakerphoneOn());
            if (audioManager.isSpeakerphoneOn()) {
                audioManager.setSpeakerphoneOn(false);
                mSensorManager.unregisterListener(this);
            }
            break;
        case TelephonyManager.CALL_STATE_OFFHOOK:
            System.out.println("My Call OFFHOOK");
            CallState = true;
            StartAudioSpeacker();
            System.out.println("Is phone speaker : "+ audioManager.isSpeakerphoneOn());
            break;
        case TelephonyManager.CALL_STATE_RINGING:
            System.out.println("My Call RINGING");
            break;
        }
    }

I dont think this is possible. The proximity sensor is managed by the operating system. To protect users apps can't directly change os files without root access.

The sensor API defined in Android defines the proximity to be a boolean i.e NEAR(1) OR FAR(0). By "sensitivity", i presume you mean the threshold distance below which the proximity sensor reports proximity as NEAR.

More details of Light/Proximity sensor on Android.

Android (upto v4.1 "jelly-bean") does NOT expose the proximity distance parameter as part of its sensor API.

You have the following options:

  • modify the sensor-HAL to add a configurable threshold to proximity sensor.

  • interact with the proximity sensor driver directly (usually a sys-fs entry).
    Depending upon the light/proximity sensor hardware in use,
    this maybe possible on few devices and not on others.

Also one would definitely require the Android device to be rooted for such "system-level" modifications.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!