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);
in your Activity onCreate() you will be able to do what you want even if the screen is locked.
精彩评论