Question

I am using the Sensor.TYPE_GRAVITY in my pedometer implementation. However, I am not sure if this sensor is indeed always implemented on devices. The sensortype is available since android 2.3, so my question is: can I assume all devices implement this sensor on android 2.3+?

I am asking, because it's a software sensor, not a hardware sensor.

Was it helpful?

Solution

Well, it looks like the implementation in 2.3 is completely software based and based only on the accelerometer data. GravitySensor.cpp in android 2.3

So it can be safe to assume in android 2.3+ it's always available.

In android 4+ the sensor is a sensor fusion device (GravitySensor.cpp in android 4.0.3), and thus also uses other sensors to increase reliability. Again, I assume it will be available and uses whatever data is can get, it would be strange to assume it suddenly drops support if for example the accelerometer is not there.

The implementation in android 2.3 uses a 2nd order Butterworth filter to extract the gravity component and is fairly simple. Experiments with this sensor on android 2.3 shows indeed that it's not completely accurate, it misses 0.1G-0.2G or the real 1G expected signal, but it's usable enough to integrate into a pedometer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top