C# 带有自定义控件的Xamarin.Android通知在API26中不起作用
我有一个通知,显示启动计时器的按钮。此按钮在API25上工作正常,但在API26及更高版本上,此按钮不起任何作用 我已经设置了一个通知通道。通知本身显示正确,因此我认为这不是频道问题 我在这里添加播放/暂停意图C# 带有自定义控件的Xamarin.Android通知在API26中不起作用,c#,xamarin.android,android-notifications,C#,Xamarin.android,Android Notifications,我有一个通知,显示启动计时器的按钮。此按钮在API25上工作正常,但在API26及更高版本上,此按钮不起任何作用 我已经设置了一个通知通道。通知本身显示正确,因此我认为这不是频道问题 我在这里添加播放/暂停意图 var playPauseIntent = new Intent("com.example.example.timer"); var timerNotificationIntentValue = this.GetTimerNotificationIntentValue(timerActi
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上,当我点击按钮时,我到达广播接收器,而在API26上,我没有改变这一点
var playPauseIntent = new Intent("com.example.example.timer");
到
现在它似乎工作正常。我在安卓8.0上可以使用你的代码,我不知道为什么不在你这边工作,也许你可以尝试添加
playbauseintent.SetClass(这个,typeof(你的广播接收器))代码>,或者您可以共享您的项目,我将测试它。对不起,我无法共享项目代码。它与setClass一起工作吗?不,它不工作。我不明白问题是什么。。。代码似乎是OK是的,我用上面的代码进行测试,它是有效的
var playPauseIntent = new Intent(this.context, typeof(MyNotificationBroadcastReceiver));