“Shake” app to respond at any time

家住魔仙堡 提交于 2020-01-05 05:16:06

问题


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.


回答1:


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

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).



来源:https://stackoverflow.com/questions/17189449/shake-app-to-respond-at-any-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!