1

I'm developing an Xamarin.Forms app and I need to handle the Push Notifications on the Android app. I need to have a button on the notification that the user is seeing and he can click on it. Here is the notification that I'm building according to Azure MSDN documentations:

void createNotification(string title, string desc)
{
    //Create notification
    var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;

    //Create an intent to show ui
    var uiIntent = new Intent(this, typeof(MainActivity));

    //Use Notification Builder
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    //Create the notification
    //we use the pending intent, passing our ui intent over which will get called
    //when the notification is tapped.


    var notification = builder.SetContentIntent(PendingIntent.GetActivity(this, 0, uiIntent, 0))
        .SetSmallIcon(Resource.Drawable.ic_stat_ic_notification)
        .SetTicker(title)
        .SetContentTitle(title)
        .SetContentText(desc)
        //.AddAction(new NotificationCompat.Action())


        //Set the notification sound
        .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))

        //Auto cancel will remove the notification once the user touches it
        .SetAutoCancel(true).Build();

    //Show the notification
    notificationManager.Notify(1, notification);
}

How do I add a button and how to trigger it so when it has been pressed how do I invoke a method?

Thanks.

Dawid Rutkowski
  • 2,658
  • 1
  • 29
  • 36
iseif
  • 297
  • 2
  • 14
  • 1
    Should be the same as doing it in Native android, and there are answers for that: http://stackoverflow.com/questions/16195800/how-to-add-button-to-notifications-in-android , http://stackoverflow.com/questions/21925688/adding-button-action-in-custom-notification , and androids guide: https://developer.android.com/guide/topics/ui/notifiers/notifications.html section "Applying an expanded layout to a notification." – jgoldberger - MSFT Dec 08 '16 at 21:29
  • This question is about Xamarin this is not a duplicate. – Minimus Heximus Jan 03 '21 at 08:18

0 Answers0