有没有一种方法,使Android应用到硬件按钮响应,同时手机上锁? [英] Is there a way to make an android app respond to hardware buttons while phone locked?
问题描述
我的工作我的第一个Android应用程序。到目前为止,我有反应,点击硬件音量控制的活动。这是很容易做到,但这样的应用程序响应来自硬件按钮这些事件即使手机被锁定我不知道是否有一种方法,使之?
I'm working on my first android app. So far I have an activity that reacts to clicks on the hardware volume controls. That's was easy to do, but I'm wondering if there is a way to make it so the app responds to these events from the hardware buttons even while the phone is locked?
我真的很为这是否可以做一个确认。如果有人可以证实,给我的如何做到这一点的总体思路,将是真棒。
I'm really looking for a confirmation of whether or not this can be done. If someone could confirm and give me the general idea of how to do it that would be awesome.
推荐答案
我还没有正是这一点这样做,但我相信,如果你把
I have not done exactly this but I believe that if you put
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
在活动的onCreate(),你就可以做你想做的,即使屏幕被锁定。
in your Activity onCreate() you will be able to do what you want even if the screen is locked.
这篇关于有没有一种方法,使Android应用到硬件按钮响应,同时手机上锁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!