Used LG Nexus 4, Android 4.3
The return value is sometimes false and I don't understand why. Documentation says: "true if the sensor is supported and successfully enabled."
What is strange is that no examples I've seen is testing return value from SensorManager.registerListener.
Strange is it also that if I ignore that a false value is returned then everything works as expected!
Documentation: http://developer.android.com/reference/android/hardware/SensorManager.html
android.hardware.SensorManager, android.hardware.SystemSensorManager
My code:
SensorManager sensorMgr = (SensorManager)_context.getSystemService(Context.SENSOR_SERVICE);
if (sensorMgr == null) {
Log.w(TAG, "200410::Sensors not supported");
return false;
}
Sensor sensor = sensorMgr.getDefaultSensor(Sensor.TYPE_PROXIMITY);
result = sensorMgr.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
if( result == false) {
// Normally something should be done here
// since the false return value indicated that registration failed.
// But I found it's better doing nothing since the registration seams to be ok
}
return result;
The strange false return value did not happened before Android 4.3
So, I everything is ok if the result value is not used like in all examples. Maybe I should be satisfied by that, but, I have 3 questions:
- Why is this return value never tested in examples?
- Why is return value false in Android 4.3?
- Why is it working even if the return value is false?
I understand these questions are difficult to answer but would be very happy if I get info that someone else have the same problem.
I got the same behavior with both Sensor.TYPE_ACCELEROMETER and Sensor.TYPE_PROXIMITY