检测在Android设备显着动态 [英] Detecting Significant Device Motion on Android

查看:271
本文介绍了检测在Android设备显着动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图找出如何使检测设备是否已经移动了显著量,更多的东西不仅仅是动摇的应用程序。我试图探测,比如说距离,至少一只脚。阅读官方Android开发网站的培训部分,我最好的猜测是,我应该使用显着的运动传感器,但我无法找到如何使用它的一个例子。难道我只是存储阵列中的我的当前的位置,然后比较一下兑事件的价值观数组,每当有一个 onTrigger() 被称为?

I've been trying to figure out how to make an application that detects whether the device has been moved a significant amount, something more than just shakes. I am trying to detect a distance of, say, at least a foot. Reading the Training section on the official Android Development site, my best guess is that I should be using the Significant Motion Sensor, but I can't find an example of how to use it. Do I just store my "current" location in an array, and then compare that versus the Event's values array whenever there is an onTrigger() is called?

或者我应该使用加速度计呢?其他一些传感器?在的LocationManager (是一个不够准确?)?

Or should I be using the accelerometer instead? Some other sensor? The LocationManager (is that one accurate enough?)?

推荐答案

根据的重大运动传感器<一个href=\"https://android.googlesource.com/platform/development/+/master/samples/ApiDemos/src/com/example/android/apis/os/TriggerSensors.java\"相对=nofollow>在ApiDemos演示活动的,没有太多的事情。该传感器TRIGER火灾,包含在 场(这是只有一个元素的数组,始终1.0根据我测试),并禁用本身。

Based on the Significant Motion Sensor demo activity in ApiDemos, there isn't much to do. The triger sensor fires, contains no meaningful data in the values field (it's an array with just one element, always 1.0 according to what I've tested) and disables itself.

所以,没有什么实际与比较。该事件解雇,仅此而已。你只需要相信它你的定义相匹配感动一个显著量:/

So, there is nothing to actually compare with. The event fired, and that's it. You'll just have to trust that it matches your definition of "moved a significant amount" :/

如果你想测量脚的顺序的距离,我是pretty确保位置的不是precise足够的(因为它是基于顶多GPS)。

If you want to measure a distance on the order of a foot, I'm pretty sure Location isn't precise enough (since it's GPS based at most).

至于加速度的数据,理论上可以,从中( - >速度 - 加速度>的距离)计算距离,但它是极不准确的。请参见这个答案,基本上声称这是不实际的。

As for Accelerometer data, you could theoretically, calculate distance from it (acceleration -> speed -> distance) but it's highly inaccurate. See this answer, which basically claims it's not practical.

这篇关于检测在Android设备显着动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆