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;
}
}
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.
来源:https://stackoverflow.com/questions/9403351/how-to-change-android-proximity-sensor-sensitivity