android.media.AudioManager.setStreamVolume(int 流类型, int 索引, int 标志)
我正在尝试更改通知的音量,但不更改铃声。 但是,当我使用此功能时,通知和铃声音量会发生变化。
示例代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为手机在声音中有一个设置--->其中有一个复选框被选中,取消选中它并再次尝试您的代码,此设置表示铃声音量将是您的通知音量,反之亦然。
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.
从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.