How to change Android proximity sensor sensitivity?

故事扮演 提交于 2019-12-08 06:21:14

问题


I coded an app based on proximity sensor, but I would like to be able to give users the ability to change the sensitivity of the sensor. Is it possible? If yes how to do it?


回答1:


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;
        }
    }



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/9403351/how-to-change-android-proximity-sensor-sensitivity

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