gpt4 book ai didi

java - Android 在广播接收器中捕获音量增大/减小按键?

转载 作者:太空宇宙 更新时间:2023-11-03 10:30:19 24 4
gpt4 key购买 nike

我正在尝试制作一个应用程序,用户可以在其中覆盖音量增大/减小按钮(以及屏幕开/关按钮 - 这可能吗?)的默认行为。无论如何,使用以下代码我可以做到这一点:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
super.onKeyUp(keyCode, event);
if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
//this is where I can do my stuff
return true; //because I handled the event
}
return false; //otherwise the system can handle it

但我希望即使应用程序未打开也能实现,因此我想设置一个广播接收器或在服务中添加一些东西以实现这一点。

感谢您的帮助。

最佳答案

as well as the screen on/off button - is this possible?

幸运的是,没有。

But I would like it to be possible even when the application is not open, hence why I'd like to set up a broadcast receiver or maybe stick something in a service to make this possible.

这对于音量按钮是不可能的。

For example, AndroSS allows you to override the camera hardware button to take a screenshot.

那是相机按钮。如果前台 Activity 不消耗相机按钮点击,则会变成广播 Intent,其他应用程序可以监听。此行为是相机和媒体按钮独有的,不与任何其他硬件按钮一起使用。

关于java - Android 在广播接收器中捕获音量增大/减小按键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6712601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com