[英]Xamarin.Android notification with custom controls does not work in API26
我有一個通知,顯示一個按鈕來啟動計時器。 此按鈕在 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));
現在它似乎工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.