Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Update an activity for a local notification

HSDRHSDR USMember ✭✭
edited October 26 in Xamarin.Forms

Hi,

I am creating a local notification and adding an activity in the android part of my xamarin forms project using this code which creates a button that says: "Start Work":

PendingIntent startWorkIntent =
PendingIntent.GetActivity(AndroidApp.Context, pendingIntentId, intent, PendingIntentFlags.UpdateCurrent);
builder.AddAction(Resource.Drawable.workGreen, "Start Work", startWorkIntent);

My question is once I have sent the message to the system using:

notification = builder.Build();
manager.Notify(messageId, notification);

how can I modify the text and the text on the button?

Currently I am canceling the notification using manager.CancelAll(); and then creating a new notification but that doesn't seem very elegant.

Also looking at the documentation for AddAction (https://docs.microsoft.com/en-us/dotnet/api/android.app.notification.builder.addaction?view=xamarin-android-sdk-9#applies-to) it states:

Warning
This API is now obsolete.

What should we be using instead of AddAction?

Best Answer

  • HSDRHSDR USMember ✭✭
    Accepted Answer

    I figured out how to update button:

    builder.MActions[0] = new NotificationCompat.Action(Resource.Drawable.restBlue, button, actionIntent);

Answers

  • HSDRHSDR USMember ✭✭
    Accepted Answer

    I figured out how to update button:

    builder.MActions[0] = new NotificationCompat.Action(Resource.Drawable.restBlue, button, actionIntent);

Sign In or Register to comment.