Xamarin. Уведомление Android с пользовательскими элементами управления не работает в API26 - PullRequest
4 голосов
/ 07 ноября 2019

У меня есть уведомление, показывающее кнопку для запуска таймера. Эта кнопка отлично работает на 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 я не

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...