"摇"应用程序可以随时响应 [英] "Shake" app to respond at any time

查看:213
本文介绍了"摇"应用程序可以随时响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的应用程序响应摇电话随时开始活动。

I want my app to start an activity at any time in response to a "shake" of the phone.

这将是最好有一个服务侦听的加速度变化后台持续运行?

Would it be advisable to have a service constantly running in the background that listens for a change in the accelerometer?

有没有人有任何其他的方式做到这一点?

Does anyone have any other way to do this?

有很多做的这种事情的应用程序。

There are plenty of apps that do this kind of thing.

推荐答案

是的,使用服务将要走的路,因为你的应用程序的needs对于 SensorEventListener 合作,运行。

Yes, using a service would be the way to go, since your app needs to be running for the SensorEventListener to work.

看看这个答案就如何实现<一个有些code href=\"http://stackoverflow.com/questions/2317428/android-i-want-to-shake-it?rq=1\">SensorEventListener (在一个活动,但类似的code可以在服务使用)。

Check out this answer for some code on how to implement a SensorEventListener (in an activity, but similar code can be used in a service).

这篇关于&QUOT;摇&QUOT;应用程序可以随时响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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