Hi!
I'm trying to read the status of the Proximity sensor (also I tryed to read the Light sensor...) using the following code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtStatus = (TextView)findViewById(R.id.txtStatus);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensorManager.registerListener(this, SensorManager.SENSOR_PROXIMITY);
}
@Override
protected void onStart() {
super.onStart();
sensorManager.registerListener(this, SensorManager.SENSOR_LIGHT);
}
@Override
public void onResume(){
super.onResume();
sensorManager.registerListener(this, SensorManager.SENSOR_LIGHT);
}
@Override
protected void onPause() {
super.onPause();
sensorManager.unregisterListener(this, SensorManager.SENSOR_LIGHT);
}
The txtStatus change the default text when there is a changing in the sensor (when I try to read the Accelerometer, it works...), but when I block the light sensor nothing happens.
When I'm in a call, the sensor works (when I put my hand blocking the sensor the screen turn off).
I'm missing something here?
Regards, André