Angelo Tricarico
Angelo Tricarico

Reputation: 1363

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?

Upvotes: 1

Views: 9337

Answers (3)

TheCodeArtist
TheCodeArtist

Reputation: 22497

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.

Upvotes: 0

Ashok Domadiya
Ashok Domadiya

Reputation: 1122

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

Upvotes: 1

ghostbust555
ghostbust555

Reputation: 2049

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.

Upvotes: 0

Related Questions