我正在开发一个适用于Android的简单指南针类型应用程序,并在Xoom WiFi上进行了测试。加速度计读数的精度始终为SensorManager.SENSOR_STATUS_UNRELIABLE
。磁场读数始终为SensorManager.SENSOR_STATUS_ACCURACY_HIGH
精度。这可能是Xoom中的错误,还是我的代码有问题?
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) {}
};
最佳答案
它看起来像是xoom中的错误。检查这些帖子:
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
关于Android Xoom加速度计的准确性始终不可靠,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5985514/