简体   繁体   中英

How to change Android proximity sensor sensitivity?

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?

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

The sensor API defined in Android defines the proximity to be a boolean ie 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.

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