我正在使用 onSensorChanged()。我应该在中指定什么?
我在这里检查了文档: http://developer.android.com/guide/topics/manifest /uses-feature-element.html
并找到了 2 个最相关的功能:
1) android.hardware.sensor.accelerometer
2) android.hardware.sensor.compass
我需要在清单中指定哪一项?或者两者都有?
是的,我确定我正在使用加速度计。但是加速度计和磁场值也用于计算“方向”(这也意味着我正在使用 android.hardware.sensor.compass ??)
这是我的代码:
@Override
public void onSensorChanged(SensorEvent event) {
int type = event.sensor.getType();
switch (type) {
case Sensor.TYPE_MAGNETIC_FIELD:
mags = event.values.clone();
break;
//I'm using Accelerometer here
case Sensor.TYPE_ACCELEROMETER:
accels = event.values.clone();
break;
}
SensorManager.getRotationMatrix(rotationMat, I, accels, mags);
SensorManager.getOrientation(rotationMat, calculatedOrients);
//I also get direction here, So do I need to specify android.hardware.sensor.compass in <uses-feature> ?
azimuth = (float) Math.toDegrees(calculatedOrients[0]);
pitch = (float) Math.toDegrees(calculatedOrients[1]);
roll = -(float) Math.toDegrees(calculatedOrients[2]);
}
提前谢谢!
I've checked the doc here:
http://developer.android.com/guide/topics/manifest/uses-feature-element.html
and found 2 most relevant features:
1) android.hardware.sensor.accelerometer
2) android.hardware.sensor.compass
Which one do I need to specify in my manifest? Or both?
Yes, I'm sure I'm using the accelerometer. But the Accelerometer and Magnetic Field values are also used to calculate "Direction" (which also means I'm using android.hardware.sensor.compass ??)
Here's my code:
@Override
public void onSensorChanged(SensorEvent event) {
int type = event.sensor.getType();
switch (type) {
case Sensor.TYPE_MAGNETIC_FIELD:
mags = event.values.clone();
break;
//I'm using Accelerometer here
case Sensor.TYPE_ACCELEROMETER:
accels = event.values.clone();
break;
}
SensorManager.getRotationMatrix(rotationMat, I, accels, mags);
SensorManager.getOrientation(rotationMat, calculatedOrients);
//I also get direction here, So do I need to specify android.hardware.sensor.compass in <uses-feature> ?
azimuth = (float) Math.toDegrees(calculatedOrients[0]);
pitch = (float) Math.toDegrees(calculatedOrients[1]);
roll = -(float) Math.toDegrees(calculatedOrients[2]);
}
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你自己回答这个问题并且应该使用两者。
确保您可以将 required 设置为 false 并让您的应用程序向用户写入通知。否则,您可能无法通过 Android Market 将其分发给旧客户端。
I think you answer it yourself and should use both.
Make sure you can set the required to false and have your application write a notice to the user. Else you might not be able to distribute it to older clients through the Android Market.