开发者

Is there a way to make an android app respond to hardware buttons while phone locked?

开发者 https://www.devze.com 2023-01-10 12:41 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号