我收到一条通知,其中显示了一个用于启动计时器的按钮。此按钮在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上却没有