开发者

Key Events through a service

开发者 https://www.devze.com 2023-03-17 23:59 出处:网络
I have a service that plays a notification sound. The sound is user defined so it can be anything. If it has a long play time I开发者_Go百科 want the user to be able to stop it by pressing any physica

I have a service that plays a notification sound. The sound is user defined so it can be anything. If it has a long play time I开发者_Go百科 want the user to be able to stop it by pressing any physical button on the phone. How do I go about setting up my OnKeyListener?


This is not possible in general.

If the device has a CAMERA or MEDIA button (latter being on wired headsets), and if the foreground activity does not consume the event, then there is a broadcast Intent (ACTION_CAMERA_BUTTON and ACTION_MEDIA_BUTTON, respectively) that you can listen for. However, relatively few devices will have one of these.

0

精彩评论

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