在不启用请勿打扰的情况下在android中启用静音模式 [英] Enable Silent Mode in android without triggering Do Not Disturb

查看:86
本文介绍了在不启用请勿打扰的情况下在android中启用静音模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

绕着这个弯头有点麻烦.

Having a little trouble bending my head around this one.

在我的音量控制应用程序中,我试图将系统声音配置文件设置为仅静音",而不会触发请勿打扰",我的应用程序有权修改DND设置和通知访问权限,在那里没有任何问题.

In my volume control app I am trying to set the system sound profile to SILENT ONLY without triggering do not disturb, my app has access to modify DND settings and notification access, no issues there.

系统设置有一个静音配置文件,可以使DND保持关闭状态,但是我找不到使用音频管理器执行此操作的方法吗?

System Settings has a silent profile that leaves DND off but I cannot find a way to do it using audio manager?

我试图将模式设置为无声,然后使用NotificationManager更改DND设置,将系统设置为无声振动后禁用DND,禁用dnd,然后将无声设置重新激活DND.

I have attempted to set the mode to silent and then change DND settings using NotificationManager, disabling DND after setting the system to silent sets vibrate, disabling dnd and then setting silent re-activates DND.

参考代码:

int current = audioManager.getRingerMode();
if (current == AudioManager.RINGER_MODE_VIBRATE) {
         newIcon = Icon.createWithResource(this, R.drawable.silent);
         //ENABLES DND WHEN IT SHOULD ENABLE SILENT
         audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}

任何帮助将不胜感激,因为这使我有点发疯.

Any assistance would be appreciated as this is driving me a little insane.

推荐答案

...,但DND是 not 沉默的.可以将DND配置为允许优先呼叫者响铃,但静音则不允许任何呼叫者响铃.因此,用户和应用程序应该可以选择.

... but DND is not silent. DND can be configured to to allow priority callers to ring, but silent allows no callers to ring. So users and apps should have the choice.

此代码似乎可以为我成功静音(在运行API 28的模拟器上),并且未设置请勿打扰模式:-

This code appears to successfully mute the ringer for me (on emulator running API 28) and does not set do-not-disturb mode:-

audio.adjustStreamVolume(AudioManager.STREAM_RING,
                        AudioManager.ADJUST_MUTE, 0);

要恢复铃声,请执行

enter audio.adjustStreamVolume(AudioManager.STREAM_RING,
                        AudioManager.ADJUST_UNMUTE, 0); 

这篇关于在不启用请勿打扰的情况下在android中启用静音模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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