Android的捕捉音量加/减键presses广播接收器? [英] Android capturing volume up/down key presses in broadcast receiver?
问题描述
我试图让一个应用程序,而用户可以更改音量加/减键的默认行为(以及开/关按钮在屏幕上 - 这可能吗?)。不管怎么说,使用一些code沿下面的线,我可以做到这一点:
@覆盖
公共布尔的onkeydown(INT键code,KeyEvent的事件){
super.onKeyUp(键code,事件);
如果((钥匙code == KeyEvent.KEY code_VOLUME_UP)){
//这是我可以做我的东西
返回true; //因为我处理的事件
}
返回false; //否则系统可以处理它
}
不过,我想这是可能的,即使在应用程序不公开,因此为什么我想建立一个广播接收器或者粘东西的服务,使这一切成为可能。
感谢您的帮助。
,以及在屏幕上/关按钮 - ?是这可能
幸运的是,没有。
不过,我想这是可能的,即使在应用程序不公开,因此为什么我想建立一个广播接收器或者粘东西的服务,使之成为可能。
这是不可能的音量按钮。
例如,AndroSS您可以覆盖摄像头硬件按钮拍摄的截图。
这是相机按钮。如果前景活动不占用拍照键点击,也被变成了广播意图
,这是其它应用程序可以监听。此行为是唯一的照相机和媒体按钮和不与任何其它硬件按钮使用。
I'm trying to make an application where the user can override the default behaviour of the volume up/down buttons (as well as the screen on/off button - is this possible?). Anyways, using some code along the lines of the following I can do this:
@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
}
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.
Thanks for any help.
as well as the screen on/off button - is this possible?
Fortunately, no.
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.
This is not possible for the volume buttons.
For example, AndroSS allows you to override the camera hardware button to take a screenshot.
That is the camera button. If the foreground activity does not consume a camera button click, that gets turned into a broadcast Intent
, which other applications can listen for. This behavior is unique to the camera and media buttons and is not used with any other hardware buttons.
这篇关于Android的捕捉音量加/减键presses广播接收器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!