我正在使用 onSensorChanged()。我应该在中指定什么?

发布于 2024-10-05 12:15:29 字数 1286 浏览 0 评论 0原文

我在这里检查了文档: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梅倚清风 2024-10-12 12:15:29

我认为你自己回答这个问题并且应该使用两者

确保您可以将 required 设置为 false 并让您的应用程序向用户写入通知。否则,您可能无法通过 Android Market 将其分发给旧客户端。

<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
<uses-feature android:name="android.hardware.sensor.compass" android:required="true" />

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.

<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
<uses-feature android:name="android.hardware.sensor.compass" android:required="true" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文