禁用卷吐司 [英] Disable the Volume Toast

查看:161
本文介绍了禁用卷吐司的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用增加的AudioManager量。

I'm trying to increase the volume using AudioManager.

但它显示的Andr​​oid原生UI卷(卷搜索栏)toast.I要禁用它。
我知道这是可以使用关键事件的活动有可能,但我想通过服务来做到这一点。
如何禁用敬酒?
这里是土司的截图:结果

But it showing Native Android Volume UI(Volume Seekbar) toast.I want to disable this. I know this can be possible in Activity using Key Event but i want to do it through service. How to disable the toast? Here is a screenshot of the toast:

推荐答案

AudioManager 级提供了以下方法来调整某些流的音量:

The AudioManager-class offers the following methods to adjust the volume of certain streams:

所有这些方法都带有标志 -parameter作为他们的最后一个参数。这对你有意思的标志是<一个href=\"http://developer.android.com/reference/android/media/AudioManager.html#FLAG_SHOW_UI\"><$c$c>FLAG_SHOW_UI其中:

All those methods take a flag-parameter as their last argument. The flag which is interesting for you is the FLAG_SHOW_UI which:

显示包含当前音量敬酒。

Show a toast containing the current volume.

因此​​,要摆脱吐司,的不供应这个标志(或整型值1),但提供所有其它标志(如需要),或只是 0

So, to get rid of the Toast, don't supply this flag (or the int-value 1) but supply all your other flags (if needed) or just 0:

AudioManager manager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
manager.adjustVolume(AudioManager.ADJUST_RAISE, 0);

以上code-片段对我的作品在Android 4.0.4(摩托罗拉Xoom)和Android 2.3.5(HTC Desire HD的)。

The above code-snippet works for me on Android 4.0.4 (Motorola Xoom) and Android 2.3.5 (HTC Desire HD).

这篇关于禁用卷吐司的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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