Таким образом, я смог выяснить, что (я думаю) мне нужно, следуя некоторым из ответов Барела, а также некоторым другим страницам SO и складывая это воедино.
Я уверен, что я бегу в некоторые изменения, которые мне нужно сделать позже, но на данный момент это привело меня к тому, что у меня могло быть 2 действия (Принять, Отклонить), выбрать любую из кнопок действий, а затем нажать несколько логик c, куда я собираюсь реализовать то, что я хочу сделать с обоими действиями.
SendLocalNotification * метод 1007 * в FirebaseService класс:
void SendLocalNotification(string body)
{
//Unique request code to avoid PendingIntent collision.
var requestCode = new Random().Next();
// accept
var acceptIntent = new Intent(this, typeof(MainActivity));
acceptIntent.SetAction("ACCEPT_ACTION");
var pendingIntentAccept = PendingIntent.GetActivity(this, requestCode, acceptIntent, PendingIntentFlags.OneShot);
// decline
var declineIntent = new Intent(this, typeof(MainActivity));
declineIntent.SetAction("DECLINE_ACTION");
var pendingIntentDecline = PendingIntent.GetActivity(this, requestCode, declineIntent, PendingIntentFlags.OneShot);
var notificationBuilder = new NotificationCompat.Builder(this)
.AddAction(0, "Accept", pendingIntentAccept)
.AddAction(0, "Decline", pendingIntentDecline)
.SetContentTitle("Load Match")
.SetSmallIcon(Resource.Drawable.laundry_basket_icon_15875)
.SetContentText(body)
.SetAutoCancel(true)
.SetShowWhen(false)
.SetContentIntent(pendingIntentAccept)
.SetContentIntent(pendingIntentDecline);
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
{
notificationBuilder.SetChannelId(AppConstants.NotificationChannelName);
}
var notificationManager = NotificationManager.FromContext(this);
notificationManager.Notify(0, notificationBuilder.Build());
}
И тогда у меня было обновить мои OnNewIntent переопределить в MainActivity . Обратите внимание на manager.CancelAll()
. Я должен был сделать это, чтобы фактически удалить уведомление из моей панели после нажатия действия:
protected override void OnNewIntent(Intent intent)
{
switch (intent.Action)
{
case "ACCEPT_ACTION":
Console.WriteLine("hit accept action case.");
break;
case "DECLINE_ACTION":
Console.WriteLine("hit decline action case.");
break;
default:
Console.WriteLine("didn't hit either action.");
break;
}
var manager = (NotificationManager)this.GetSystemService(Context.NotificationService);
manager.CancelAll();
base.OnNewIntent(intent);
}