检测用户是否与手机交互?
我需要检测用户何时与手机交互,并在上次用户触摸屏幕 60 秒后重新启动我的应用程序。可以做这样的事情吗? 它必须作为 PC 的屏幕服务器。
I need to detect when user interacts with the phone and restart my app after 60 seconds from last user's touch on screen. Is is possible to do something like that?
It must work as the screenserver for PC.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ACTION_USER_PRESENT
是一个广播操作,因此您应该能够编写一个广播接收器来响应它并启动您的应用程序。请记住,ACTION_USER_PRESENT
是我还刚刚遇到一个 示例,其中
BOOT_COMPLETED< /code> 广播操作由广播接收器用来在启动时启动应用程序。
ACTION_USER_PRESENT
is a broadcast action, so you should be able to write a broadcast receiver to respond to it and launch your application. Keep in mind thatACTION_USER_PRESENT
isI also just came across an example where the
BOOT_COMPLETED
broadcast action is used by a broadcast receiver to start an application on boot.仅当您的活动位于前台时,在这种情况下您可以跟踪触摸事件。您无法了解系统其他地方发生的触摸事件。
Only if your activity is in the foreground, in which case you can keep track of touch events. You cannot find out about touch events happening elsewhere in the system.
根据android生命周期,如果用户按下home按钮或键盘锁定onPause将被调用。所以做这样的事情。
如果用户在 60 秒之前到达,则在
onRestart()
中。According to android lifecycle if user press home button or keypad locked onPause will get called.So do something like this.
and if user comes before 60 seconds then in
onRestart()
.