Android Xoom accelererometer accuracy is always unreliable

蹲街弑〆低调 提交于 2019-12-10 13:17:05

问题


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) {}
};

回答1:


It looks like a bug in the xoom. Check these posts:

http://community.developer.motorola.com/t5/Android-App-Development-for/Xoom-magnetometer-Y-axis-always-reads-zero/td-p/14184

http://community.developer.motorola.com/t5/Android-App-Development-for/Q-Compass-Behavior-when-Xoom-is-held-in-different-orientations/td-p/14332




回答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.




回答3:


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. :-)



来源:https://stackoverflow.com/questions/5985514/android-xoom-accelererometer-accuracy-is-always-unreliable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!