所以我正在编写一款应用程序,其目的是将手机设置为全音量模式,即使是请勿打扰模式。我的应用具有通知过滤器更改权限,因此我可以将其从DnD模式中取出。甜。我通过记录了解到,当我以编程方式关闭DnD模式时,振铃模式设置为正常,振铃音量设置为1.但是当我使用setStreamVolume达到最大音量时,它不会改变音量。更值得注意的是,我也无法通过音量摇杆手动调高音量。我已经想出如何在退出DnD模式后立即增加铃声音量的唯一方法是使用屏幕上的音量滑块。另一点是,当环音量设置为大于1的任何值,然后我测试我的应用程序时,setStreamVolume工作。我在这里错过了什么吗?这是一些代码。
这是我的接收器,可以检测DnD模式何时发生变化。
public void onReceive(Context context, Intent intent) {
if(intent.getAction() !=null && intent.getAction().equals(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED)) {
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (mNotificationManager.getCurrentInterruptionFilter() == NotificationManager.INTERRUPTION_FILTER_ALARMS) {
Log.i("NotificationFilter", "filter alarms");
} else if (mNotificationManager.getCurrentInterruptionFilter() == NotificationManager.INTERRUPTION_FILTER_ALL) {
AudioManager am = (AudioManager)context.getSystemService(AUDIO_SERVICE);
Log.i("NotificationFilter", "filter all, " + am.getStreamVolume(STREAM_RING));
int vol = am.getStreamMaxVolume(AudioManager.STREAM_RING);
am.setStreamVolume(AudioManager.STREAM_RING, vol, FLAG_SHOW_UI);
}
}
}