I have implemented an application that incorporates the following sensors:
- Accelerometer
- Magnetic Field
- Orientation (deprecated)
- Gyroscope
- Gravity
This is a sample code of onSensorChanged() method:
@Override
public void onSensorChanged(SensorEvent event) {
int type = event.sensor.getType();
if (event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
if (type == Sensor.TYPE_GYROSCOPE) {
// Log.e(TAG, "Unreliable gyroscope");
} else if (type == Sensor.TYPE_GRAVITY) {
// Log.e(TAG, "Unreliable gravity");
}
return;
}
if (type == Sensor.TYPE_ACCELEROMETER) {
mmAcceleration = event.values.clone();
} else if (type == Sensor.TYPE_MAGNETIC_FIELD) {
mmGeomagnetic = event.values.clone();
} else if (type == Sensor.TYPE_GYROSCOPE) {
mmRotation = event.values.clone();
} else if (type == Sensor.TYPE_ORIENTATION) {
mmOrientation = event.values.clone();
} else if (type == Sensor.TYPE_GRAVITY) {
mmGravity = event.values.clone();
}
if (mmAcceleration != null && mmGeomagnetic != null
&& mmOrientation != null) {
// Handling the data ...
mmAcceleration = null;
mmGeomagnetic = null;
mmRotation = null;
mmOrientation = null;
mmGravity = null;
}
}
The devices that I have tried the code on are HTC One S. I have tried it on 3 discrete devices. Also I have calibrated the G-sensor multiple times and then started the application but I still keep getting unreliable results. Also I have tried to calibrate, restart the phone and then calibrate again, or even after restart run directly my application. The other sensors work fine. Also I have tried different environments (indoor) and I am not close to any source of interference.
I still get unreliable (SENSOR_STATUS_UNRELIABLE) results for Gyroscope and gravity (uses gyroscope) sensors.
Do you have any suggestion about what may going wrong?
Thank you in advance.