Used LG Nexus 4, Android 4.3
The return value is sometimes false, and I do not understand why. The documentation says: "true if the sensor is supported and successfully turned on."
It is strange that no examples that I saw check the return value from SensorManager.registerListener.
It is also strange that if I ignore that a false value is returned, everything works as expected!
Documentation: http://developer.android.com/reference/android/hardware/SensorManager.html
android.hardware.SensorManager, android.hardware.SystemSensorManager
My code is:
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) {
Strange false return value didn't happen before Android 4.3
So, I'm fine if the result value is not used, as in all examples. Maybe I should be satisfied with this, but I have 3 questions:
- Why has this return value never been tested in the examples?
- Why is false returned in Android 4.3?
- Why does it work even if the return value is false?
I understand that these questions are difficult to answer, but I will be very happy if I get information that someone else has a problem.
I got the same behavior with both Sensor.TYPE_ACCELEROMETER and Sensor.TYPE_PROXIMITY