Android 警报不响';静音/优先模式下的t环

Android 警报不响';静音/优先模式下的t环,android,xamarin,notifications,alarmmanager,android-alarms,Android,Xamarin,Notifications,Alarmmanager,Android Alarms,在Android 5+中,下面的代码应该在静默/优先模式下响起,但我发现如果在截止日期前几个小时设置了静默/优先模式,它实际上不会响起。但是,通知本身显示正确,但已静音。有人知道实现这一点的方法吗,或者是一种解决方法?提前谢谢 var alarmManager = (AlarmManager) Activity.GetSystemService(Context.AlarmService); var intent = new Intent (Context, typeof(AlarmReceive

在Android 5+中,下面的代码应该在静默/优先模式下响起,但我发现如果在截止日期前几个小时设置了静默/优先模式,它实际上不会响起。但是,通知本身显示正确,但已静音。有人知道实现这一点的方法吗,或者是一种解决方法?提前谢谢

var alarmManager = (AlarmManager) Activity.GetSystemService(Context.AlarmService);
var intent = new Intent (Context, typeof(AlarmReceiver));
var pendingIntent = PendingIntent.GetBroadcast (Context, 0, intent,
    PendingIntentFlags.UpdateCurrent);
// milliseconds is a double containing those from now to the alarm time
alarmManager.SetExact (AlarmType.RtcWakeup, milliseconds, pendingIntent);
报警接收器:

var notificationIntent = new Intent (context, typeof(MyActivity));
var contentIntent = PendingIntent.GetActivity (context, 0, notificationIntent,
    PendingIntentFlags.CancelCurrent);
var manager = NotificationManagerCompat.From (context);
var notification = new NotificationCompat.Builder (context)
    .SetContentIntent (contentIntent)
    .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
    // Yes, I'm using a custom sound (MP3)
    .SetSound(soundUri)
    .SetCategory(Notification.CategoryAlarm)
    .Build();

manager.Notify(0, notification);
我想这会有帮助的

尝试向通知添加优先级,然后添加AudioAttributes对象作为setSound的第二个参数。我认为系统正在播放您的声音,音频流已被静音。从链接的问题中:

AudioAttributes.Builder attrs = new AudioAttributes.Builder();
attrs.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION);
attrs.setUsage(AudioAttributes.USAGE_ALARM);

notification.setPriority(Notification.PRIORITY_MAX);
notification.setSound(soundUri, attrs.build());
编辑: 请注意,如果设备已完全打开“请勿打扰”(完全静音),则无论您在此处设置了什么属性,系统都不会播放通知声音。

我认为这会有所帮助

尝试向通知添加优先级,然后添加AudioAttributes对象作为setSound的第二个参数。我认为系统正在播放您的声音,音频流已被静音。从链接的问题中:

AudioAttributes.Builder attrs = new AudioAttributes.Builder();
attrs.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION);
attrs.setUsage(AudioAttributes.USAGE_ALARM);

notification.setPriority(Notification.PRIORITY_MAX);
notification.setSound(soundUri, attrs.build());
编辑:
请注意,如果设备已完全打开“请勿打扰”(完全静音),则无论您在此处设置了什么属性,系统都不会播放您的通知声音。

谢谢,伙计,我最终通过一个解决方法使其工作,即在被阻止的屏幕上显示一个活动,然后在屏幕上播放MP3。谢谢,伙计,我最终通过一个变通办法让它工作了,在被屏蔽的屏幕上显示一个活动,然后我在那里播放MP3。