把棒棒糖成静音模式/静音模式没有优先模式模式、静音、棒棒糖

2023-09-06 07:06:00 作者:一追再追

目前我使用的是下面把手机变成静音模式:

At the moment I am using the following to put the phone into Silent Mode:

AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);

不过,我注意到,在棒棒堂它使手机进入优先模式与在通知栏顶部有一个小明星。但我希望它是100%的沉默,而不是优先模式。这可能吗?要设置棒棒堂100%沉默?

But I have noticed that in Lollipop it puts the phone into "Priority Mode" with a little star at the top in the notification bar. But I want it to be 100% silent and not "Priority Mode". Is this possible? To set Lollipop to be 100% silent?

我曾尝试到setRingerMode设置为0,这样

I have tried to set the setRingerMode to 0 like this

audioManager.setRingerMode(0);

但它仍然给我的明星,而不是扬声器与线通过它,它在括号下它说用振动(优先级)。

But it still gives me the star instead of the the speaker with the line through it and it says Vibrate with (Priority) in brackets under it.

推荐答案

在的Andr​​oid 5.0.X,称 setRingerMode(RINGER_MODE_SILENT)将(我)触发优先模式这将(ⅱ)随后触发振铃模式的变回RINGER_MODE_NORMAL。

In Android 5.0.X, calling setRingerMode(RINGER_MODE_SILENT) would (i) trigger the "priority mode", which would (ii) subsequently trigger a change of the ringer mode back to RINGER_MODE_NORMAL.

有一个残酷的解决方法是,利用在Android中5.0.X的一个bug,是发出 setRingerMode(RINGER_MODE_SILENT)在短时间内操作后再次调用(比如500毫秒)( ⅱ)上述被触发。但是,这当然是不妥当,应该停止在从Android 5.1.x工作。

A brutal workaround, exploiting a bug in Android 5.0.X, is to issue the setRingerMode(RINGER_MODE_SILENT) call again in a short time (say 500ms) after action (ii) above is triggered. But this is of course not proper and should cease to work in Android 5.1.X.

实现5.X 100%的沉默的正确方法是将切换到无中断模式。这可以通过创建扩展服务 NotificationListenerService 来实现,对其进行注册,并提供一个函数调用来设置中断模式 requestInterruptionFilter(INTERRUPTION_FILTER_NONE)的服务。 在这里(Noyze应用程序)是一个例子。然后,您可以从您的活动调用函数切换到模式。

The proper way to achieve 100% silence in 5.X would be to switch to the "None" interruption mode. This could be achieved by creating a service extending NotificationListenerService, registering it, and providing a function to set the interruption mode by calling requestInterruptionFilter(INTERRUPTION_FILTER_NONE) in the service. Here (Noyze app) is an example. You can then invoke the function from your activity to switch to the mode.

对于这个工作,你需要在 BIND_NOTIFICATION_LISTENER_SERVICE 权限,由用户接入的通知明确授权。

For this to work you would need the BIND_NOTIFICATION_LISTENER_SERVICE permission, and an explicit grant of notification access by the user.

注意:你可能知道 INTERRUPTION_FILTER_NONE 到底意味着100%的沉默,闹钟会停止工作。

Caution: as you may be aware INTERRUPTION_FILTER_NONE really means 100% silence, and Alarm clock would cease to work.

 
精彩推荐
图片推荐