在Android应用程序的音量控制 [英] Volume Control in android application

查看:105
本文介绍了在Android应用程序的音量控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何控制从音量键我的应用程序的音量(违背我的信仰,我读过他们只控制振铃音量)。我应该覆盖onKey下/上?

I'd like to know how to control my application's volume from the volume keys (contrary to my belief , I've read they control only the ringer volume). Should I overwrite the onKey Down/Up?

或者是有做到这一点其他的方式?我问,因为如果我覆盖上提到的功能活动,则该功能将只接收如果与本次活动相关的视图具有焦点的事件,我在寻找的东西Globaly(工作无不管是什么活动,现在正在运行)

Or is there other way to accomplish this? I'm asking because if I overwrite the upper mentioned function for an activity, then the functions will receive the event only if a view associated with the this activity has the focus, and I'm looking for something "Globaly" ( to work no matter what activity is running now)

推荐答案

还有一个<一个href="http://stackoverflow.com/questions/628659/how-can-i-manage-audio-volumes-sanely-in-my-android-app/674207#674207">question从很久以前的问了同样的事情。从本质上讲,答案是:不会覆盖的onkeydown和的onkeyup的按钮。这是更好的做法简单地使用这一行 setVolumeControlStream(AudioManager.STREAM_MUSIC); 在你的onCreate()方法。这告诉音量按钮应该影响媒体音量,当你的应用程序是可见的操作系统,这是它使用您的应用程序的音量。

There was another question from a long time ago that asked the same thing. Essentially the answer is: don't override the onKeyDown and onKeyUp buttons. It's much better to simply use this one line setVolumeControlStream(AudioManager.STREAM_MUSIC); in your onCreate() method. That tells the OS that the volume buttons should affect the "media" volume when your application is visible, and that's the volume it uses for your application.

作为控制媒体音量,无论是什么应用程序是可见的,我不知道可以做 - 或者如果可以,是否这将是一件好事。

As for controlling the Media volume no matter what app is visible, I'm not sure that can be done - or if it could, whether that would be a good thing.

这篇关于在Android应用程序的音量控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆