ANDROID:如何从 Sensor.TYPE_LINEAR_ACCELERATION 检索值?
当使用经典的 TYPE_ACCELEROMETER 传感器时,您可以执行以下操作:
public void onSensorChanged(SensorEvent sensorEvent){
if (sensorEvent.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
ax=sensorEvent.values[0];
}
}
但是,当使用 TYPE_LINEAR_ACCELERATION 时,它应该如何提供信息?
我尝试过做类似的事情:
public void onSensorChanged(SensorEvent sensorEvent){
if (sensorEvent.sensor.getType()==Sensor.TYPE_LINEAR_ACCELERATION){
ax=sensorEvent.values[0];
}
}
但它不起作用。我看过帖子了 Android TYPE_LINEAR_ACCELERATION 传感器 - 它显示什么? 我还查看了官方文档: 传感器 和 SensorEvent 这确实很有趣,但不要谈论他们是如何采集样本的。有什么想法吗?
When using the classic TYPE_ACCELEROMETER sensor, you can do something like:
public void onSensorChanged(SensorEvent sensorEvent){
if (sensorEvent.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
ax=sensorEvent.values[0];
}
}
BUT, when using TYPE_LINEAR_ACCELERATION, how is it supposed to provide the info?
I've tried to do things like:
public void onSensorChanged(SensorEvent sensorEvent){
if (sensorEvent.sensor.getType()==Sensor.TYPE_LINEAR_ACCELERATION){
ax=sensorEvent.values[0];
}
}
But it's not working. I've seen the post
Android TYPE_LINEAR_ACCELERATION sensor - what does it show?
And also I've looked the official documentation:
Sensor and
SensorEvent
Which are very interesting indeed, but don't talk about how they took the samples. Any Idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这是
我的错,因为我没有正确注册监听器。
因此,总而言之:
TYPE_LINEAR_ACCELERATION
的使用方式与传统的TYPE_ACCELEROMETER
类似。Ok, it's with
It was MY fault, because I didn't register the listener properly.
So, In conclussion:
TYPE_LINEAR_ACCELERATION
is used like the tradiotionalTYPE_ACCELEROMETER