android.media.AudioManager.setStreamVolume(int 流类型, int 索引, int 标志)

发布于 2024-11-15 14:19:32 字数 734 浏览 4 评论 0原文

我正在尝试更改通知的音量,但不更改铃声。 但是,当我使用此功能时,通知和铃声音量会发生变化。

示例代码:

AudioManager mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
int volNot = mAudioManager.getStreamVolume(STREAM_NOTIFICATION);
int volRing = mAudioManager.getStreamVolume(STREAM_RING);
Log.d(volNot + "," + volRing, "not, ringer");
mAudioManager.setStreamVolume(STREAM_NOTIFICATION, 1,  0);
volNot = mAudioManager.getStreamVolume(STREAM_NOTIFICATION);
volRing = mAudioManager.getStreamVolume(STREAM_RING);
Log.d(volNot + "," + volRing, "not, ringer");

对于结果 setStreamVolume(STREAM_NOTIFICATION, 1, 0)notifications(STREAM_NOTIFICATION) 的值更改为 1,但它也会更改 ringer(STREAM_RING) 的值 到 1。

I am trying to change volume of notifications, but not ringer.
However, when I use this function notification and ringer volume are changed.

Example code:

AudioManager mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
int volNot = mAudioManager.getStreamVolume(STREAM_NOTIFICATION);
int volRing = mAudioManager.getStreamVolume(STREAM_RING);
Log.d(volNot + "," + volRing, "not, ringer");
mAudioManager.setStreamVolume(STREAM_NOTIFICATION, 1,  0);
volNot = mAudioManager.getStreamVolume(STREAM_NOTIFICATION);
volRing = mAudioManager.getStreamVolume(STREAM_RING);
Log.d(volNot + "," + volRing, "not, ringer");

For result setStreamVolume(STREAM_NOTIFICATION, 1, 0) changes value of notifications(STREAM_NOTIFICATION) to 1, but it also changes value of ringer(STREAM_RING) to 1.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月如刀 2024-11-22 14:19:32

这是因为手机在声音中有一个设置--->其中有一个复选框被选中,取消选中它并再次尝试您的代码,此设置表示铃声音量将是您的通知音量,反之亦然。

This is because the phone has a setting in sounds---> volume in which there is a tick box which is checked, uncheck it and try your code again, this setting says that the ringer volume will be your notification volume and visa-verse.

攒眉千度 2024-11-22 14:19:32

从ICS(Android 4.0)开始,Ringer和Notification共享官方Android ROMS中的音量流。在此之前,用户可以选择拆分流。

Since ICS (Android 4.0), Ringer and Notification shares volume stream in official Android ROMS. Before this, user could choose to split the streams.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文