用在我的应用程序音量按钮 - 安卓 [英] Android - Volume Buttons used in my application
本文介绍了用在我的应用程序音量按钮 - 安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用音量按钮来控制我的应用程序中的变量参数。
我用 Activity.onKeyDown
来得到通知时,该按钮pssed $ P $但媒体的体积也增大。
Android正在做类似下面的时候我preSS音量键:
I need to use volume buttons to control a variable parameter in my application.
I use Activity.onKeyDown
to get notified when the button is pressed but the media volume is also increased.
Android is doing something like below when I press the volume key:
- 在增加媒体/铃声音量
- 事件传递给我的应用程序
有没有一种方法,以避免增加系统的体积和使用音量键只为我的应用程序?
Is there a way to avoid increasing the system volume and use volume key only for my application?
推荐答案
您需要捕获所有操作:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_DOWN) {
//TODO
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_DOWN) {
//TODO
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}
这篇关于用在我的应用程序音量按钮 - 安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文