gpt4 book ai didi

安卓 : How to bypass Do Not Disturb So that it plays notification audio in background

转载 作者:行者123 更新时间:2023-12-05 07:16:21 24 4
gpt4 key购买 nike

我的目标是 Android 8.0 及更高版本,并希望我的远程通知在

a) 设备处于请勿打扰模式(启用异常(exception))

b) 设备在后台。

当不处于 DND 模式时,通知会按预期工作。在 DND 模式下,在前台有一个视觉通知,但在后台没有音频。

我的 channel 设置如下:

private void InitialiseNotificationChannel(NotificationManager notificationManager, string channelID, string name, string soundFilename)
{
// create channel
NotificationChannel channel = new NotificationChannel(channelID, name, NotificationImportance.High);

// create sound URI
Android.Net.Uri uri = Android.Net.Uri.Parse("android.resource://" + Application.Context.PackageName + "/raw/" + soundFilename);

// create audio attributes
AudioAttributes alarmAttributes = new AudioAttributes.Builder()
.SetContentType(AudioContentType.Sonification)
.SetUsage(AudioUsageKind.Notification).Build();

// setup channel
channel.SetSound(uri, alarmAttributes);
channel.EnableVibration(true);

channel.EnableLights(true);
channel.LightColor = Resource.Color.red;

long[] vibrationPattern = { 100, 200, 300, 400, 500, 600, 1000 };
channel.SetVibrationPattern(vibrationPattern);

// Bypass Do Not Disturb
channel.SetBypassDnd(true);
channel.LockscreenVisibility = NotificationVisibility.Public;

// add channel
notificationManager.CreateNotificationChannel(channel);
}

我还设置了过滤来处理异常:

            if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
notificationManager.NotificationPolicy = new NotificationManager.Policy(NotificationPriorityCategory.Events, NotificationPrioritySenders.Any, NotificationPrioritySenders.Any);

notificationManager.SetInterruptionFilter(InterruptionFilter.All);

我在设备上为应用程序选择了所有类型的异常,即:

所有电话,

所有消息,

警报/任务开启,

开启提醒

但是在后台收到通知时仍然没有声音。

知道我遗漏了什么吗?

谢谢

最佳答案

请记住,根据 docs , SetBypassDnd 只能由系统本身(用户点击设备设置)和通知排名器修改。

关于安卓 : How to bypass Do Not Disturb So that it plays notification audio in background,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59264109/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com