有谁知道简单震动检测器的示例代码?
我正在寻找一个 android 代码示例,了解如何让我的手机监听“摇动”,然后让它触发 webview.reload();只需重新加载活动上的网络视图即可。有人对这个话题有任何见解吗?
I'm looking for an android code example on how I would be able to make my phone listen for a "shake" and then have it trigger webview.reload(); to simply reload the webview on the activity. Anyone have any insight on this topic?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试 这个中的
Shaker
类项目。You can try the
Shaker
class from this project.我认为它就像读取加速度一样简单,观察 x 加速度,寻找大约 1G 的 pos 峰值(这个样本是第一个小于前几个样本的样本),增加一个计数器。经过三次“摇动”后,您就变成了金色。您有 2 个参数需要调整……阈值和次数。
I think its just as simple as read the accel, watch the x accel, look for a pos peak about 1G, (this sample is the first that is less than the previous couple of samples), increment a counter. After three 'shakes', you're golden. You have 2 params to adjust... threshold and reps.