我收到一条通知,其中显示了一个启动计时器的按钮。此按钮在API25上可以正常使用,但在API26及更高版本上,该按钮不起作用。
我已经建立了一个通知频道。通知本身可以正确显示,因此我认为这不是频道问题。
我在这里添加播放/暂停意图
var playPauseIntent = new Intent("com.example.example.timer");
var timerNotificationIntentValue = this.GetTimerNotificationIntentValue(timerAction);
playPauseIntent.PutExtra("timerNotification", timerNotificationIntentValue);
const int playPauseIntentId = 0;
var playPausePendingIntent = PendingIntent.GetBroadcast(this.context, playPauseIntentId, playPauseIntent, PendingIntentFlags.UpdateCurrent);
contentView.SetOnClickPendingIntent(Resource.Id.btn_start_pause, playPausePendingIntent);
这就是我创建通知的方式
var channelId = "11e9a3a1-aebf-425d-a9e8-fcc2fb139664";
var channelName = "General";
NotificationChannel channel;
channel = notificationManager.GetNotificationChannel(channelName);
if (channel == null)
{
channel = new NotificationChannel(channelId, channelName, NotificationImportance.Max);
channel.LockscreenVisibility = NotificationVisibility.Public;
notificationManager.CreateNotificationChannel(channel);
}
channel?.Dispose();
Notification.DecoratedCustomViewStyle notificationStyle = new Notification.DecoratedCustomViewStyle();
notification = new Notification.Builder(this.context, "11e9a3a1-aebf-425d-a9e8-fcc2fb139664")
.SetSmallIcon(Resource.Drawable.ic_logo)
.SetStyle(notificationStyle)
.SetCustomContentView(contentView)
.Build();
那我就通知
notification.Flags |= NotificationFlags.OngoingEvent;
notificationManager.Notify("1", notification);
当点击按钮时,API26上没有任何反应。
我注意到的是,在API25上,当我点击按钮时,我进入了BroadcastReceiver,而在API26上,我没有
改变了这个
var playPauseIntent = new Intent("com.example.example.timer");
至
var playPauseIntent = new Intent(this.context, typeof(MyNotificationBroadcastReceiver));
现在看来工作正常。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句