Android Xoom accelererometer accuracy is always unreliable
Asked Answered
T

3

6

I'm working on a simple compass type application for Android, testing on Xoom WiFi. The accuracy of the accelerometer readings is always SensorManager.SENSOR_STATUS_UNRELIABLE. The magnetic field readings are always accuracy SensorManager.SENSOR_STATUS_ACCURACY_HIGH. Could this be a bug in the Xoom, or is there a problem in my code?

onCreate:
mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
accelGravitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
magSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

onResume:
mSensorManager.registerListener(accelListener, accelGravitySensor, SensorManager.SENSOR_DELAY_NORMAL);
mSensorManager.registerListener(magListener, magSensor, SensorManager.SENSOR_DELAY_NORMAL);

private final SensorEventListener accelListener = new SensorEventListener() {
  public void onSensorChanged(SensorEvent event) {
    Log.d(TAG, "accel (" + event.values[0] + ", " + event.values[1] + ", " + event.values[2] + ") accuracy=" + accuracyTag(event.accuracy));
  }
  public void onAccuracyChanged(Sensor sensor, int accuracy) {}
};
Taxi answered 12/5, 2011 at 23:4 Comment(0)
B
2

The Nexus S has this problem too (with the gyroscope), and it looks like it's due to a lazy driver writer who forgot to set the accuracy field of the reading ;)

As long as the data's fine, this should be purely cosmetic.

Bastion answered 26/5, 2011 at 16:25 Comment(0)
V
1

I don't know if you're having problems with the compass accuracy, but I know I did when I used

magSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD)

I highly recommend using something more like the following.

    mySensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
    List<Sensor> mySensors = mySensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
    if(mySensors.size() > 0){
        mySensorManager.registerListener(mySensorEventListener, mySensors.get(0), SensorManager.SENSOR_DELAY_NORMAL);
        sersorrunning = true;
        Toast.makeText(this, "Start ORIENTATION Sensor", Toast.LENGTH_LONG).show(); 
    }

I found that when I used the magnetic field sensor, rather than the orientation sensor, it worked pretty well on my phone (Droid Incredible), but wen all sorts of crazy on my wife's phone (Droid Pro), and my Coworker's phone (Samsung Galaxy Tab). So you might consider changing your sensor, just for device compatibility issues. :-)

Vern answered 28/5, 2011 at 19:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.