在手机锁定时捕获硬按钮事件? [英] capture hard-button events when phone is locked?
问题描述
我目前正在收集信息,如果可以为紧急目的进行某种快速绘图应用程序;我想让设备启动一个自定义的摄像机意图一旦一些特定的键组合按下。
i am currently collecting information, if it is possible to make some kind of quickdraw-application for emergency purposes; i want to get the device to start a customized camera-intent once some certain key-combo is pressed.
我已经检查了很多关于这个主题的信息,但是我仍然不清楚这个想法是多么可行。
到目前为止,我想,这不是由android设计。我的第一个想法是构建一些类型的InputService,并让它教会硬电源按钮来听三次点击。但是服务不允许捕获KeyEvents。
I have check quite some information on the topic already, but it is still not clear to me how doable this whole idea is. So far i figured, that it is not meant to be by android-design. My first idea was to build some kind of InputService and make it teach the hard power-button to listen for a triple-click. But the Services arent allowed to catch KeyEvents. So, the volume-button is out of the equasion aswell.
然后我发现了在SCREEN ON / OFF事件上反应的想法,但是80%的ppl说它不会工作,而20%的州,他们得到它。但我不能真的确定,如果他们真的做到了。
Then i came across the idea reacting on the SCREEN ON/OFF event, but 80% of the ppl say that it is not going to work, while 20% state, that they got it. But im not really sure if they really did it.
最后但并非最不重要的问题,如果可以启动这个自定义相机意图/应用程序的锁定模式。
Last but not least the question, if it is possible to launch this customized-camera-intent/application out of the locked mode.
resumé:我需要检查它是否可能启动这个相机应用程序(这是一些快速fotos紧急目的),而手机在口袋在锁模式。任何人给我一些意见? thx
推荐答案
解决方案是设置 BroadcastReceiver
即侦听 SCREEN_ON
- 事件。我在一个 backgroundservice
中等待至少两个 SCREEN_ON
- 在短时间内的事件。 (少于两个事件显然不能工作)...
The solution is to setup a BroadcastReceiver
that is listening for the SCREEN_ON
-Event. I did this one inside a backgroundservice
that was waiting for at least two SCREEN_ON
-Events within a short period of time. (less than two events obviously can't work)...
服务
然后关闭 Keyguard
,甚至可以通过密码/手势并运行应用程序。
The Service
then dismissed the Keyguard
and was able to even pass past password/gesture and run the App. Funny fact: closing the app does pop back to desktop still beeing logged in.
我在 Android 4.2下执行此操作
..来源告诉我,解除键盘锁不能与当前的Android版本不兼容。
I did this at Android 4.2
.. Sources told me that dismissing the keyguard is not working with current Android-versions no more.
这篇关于在手机锁定时捕获硬按钮事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!