执行应用程序跳转锁屏
我想开发一个当用户拔出耳机时自动触发的应用程序。我想知道是否可以在前台自动运行它以避免解锁屏幕。
先感谢您。
I want to develop an application that triggers up automatically when the user pulls out the earphones. I would like to know if it is possible to run it in the foreground automatically avoiding the unlock screen.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用标准 API 无法做到这一点。某些应用程序可以在后台运行,但前提是它们执行某些非常具体的任务(例如,播放音频或使用 GPS 进行导航的应用程序)。但即使您这样做了,您也无法以编程方式执行以下任何操作: 1. 禁用锁定屏幕 2. 检测手机何时锁定 3. 将您的应用程序置于前台。
There's no way to do this using the standard APIs. Certain apps can run in the background, but only if they do certain very specific tasks (e.g., apps that play audio or use GPS for navigation). But even if you did that, you can't do any of these things programatically: 1. disable the lock screen 2. detect when the phone has been locked 3. bring your app to the foreground.
如果您构建服务,您可能会在后台运行。另外,您可以拦截 SCREEN_ON 或 SCREEN_OFF 事件(查找 BrodcasrReciever 以了解如何使用它)。使用该事件来执行您的代码。要禁用锁屏......很简单:
You may run in background if you build a Service. Also, you may intercept the SCREEN_ON or SCREEN_OFF event (look for a BrodcasrReciever to see how to use it). Use that events to execute your code. And to disable your lockscreen.... it's simple: