localnotificationsplugin icon indicating copy to clipboard operation
localnotificationsplugin copied to clipboard

Add extra key called "NotificationId" and its value to capture in android main activity

Open rdrscan opened this issue 8 years ago • 2 comments

Changes proposed in this pull request:

Add extra key called "NotificationId" and its value to possibility to override the method "OnNewIntent" and check this key and value in MainActivity.

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;
            base.OnCreate(bundle);
            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());
            // Add the line above
            OnNewIntent(Intent);
        }
        protected override void OnNewIntent(Intent intent)
        {
            base.OnNewIntent(intent);
            if (intent.HasExtra(LocalNotificationsImplementation.LocalNotificationIntentKey))
            {
                // Do something with the notification Id...
            }
        }
}

rdrscan avatar Apr 18 '17 17:04 rdrscan

Hi @rdrscan I got this code working thanks to you, but I don't know why when I have more than one notification on the OnNewIntent always get me the last notification Id and not the one I am click in it.

santiagobiart avatar Jun 08 '18 00:06 santiagobiart

Solved just update public void Show(string title, string body, int id, DateTime notifyTime) this line var pendingIntent = PendingIntent.GetBroadcast(Application.Context, 0, intent, PendingIntentFlags.CancelCurrent);

to this var pendingIntent = PendingIntent.GetBroadcast(Application.Context, id, intent, PendingIntentFlags.CancelCurrent);

santiagobiart avatar Jun 08 '18 20:06 santiagobiart