Xamarin Push Notifications

I know how the Push notifications work in Xamarin (Android) and how to give the Push Notifications an Intent to open an android activity.
Is there a way to instead of opening an Android activity to open an Xamarin.Forms.Xaml page. I want to open a xaml page when the user clicks on the push notification

Best Answer

Answers

  • DonaldJansenDonaldJansen USMember
    edited July 2015

    I tried the following so far but it only worked once and I did something to make it stop working, when I click on the Notification it never reaches OnHandleIntent(Intent)
    --My Service

    [Service]
    public class NotificationIntentService : IntentService
    {
        protected override void OnHandleIntent(Intent intent)
        {
    
        }
    }
    

    the intent I create is like the following

    var intent = new Intent(Application.Context.ApplicationContext, typeof(NotificationIntentService));
    Notifier.Notify(0, "Workflow", "Connected", true, false, false, intent);

    and the method Notify I have

        public static void Notify(int id, string title, string content, bool ongoing, bool sound, bool autocancel, Intent intent)
        {
            var activeContext = Application.Context.ApplicationContext;
            var builder = new Notification.Builder(activeContext)
                .SetAutoCancel(autocancel)
                .SetContentTitle(title)
                .SetSmallIcon(Resource.Drawable.icon)
                .SetContentText(content);
    
            if (sound)
            {
                builder = builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));
            }
    
            if (intent != null)
            {
                var resultPendingIntent = PendingIntent.GetService(activeContext, 0, intent, PendingIntentFlags.UpdateCurrent);
                builder = builder.SetContentIntent(resultPendingIntent);
            }
    
            builder = builder.SetOngoing(ongoing);
    
            var notificationManager = (NotificationManager)activeContext.GetSystemService(Context.NotificationService);
            var notification = builder.Build();
            notificationManager.Notify(id, notification);
        }
    
  • PaulDistonPaulDiston USUniversity ✭✭✭✭

    Hi,

    When I implemented Push Notifications I worked through the following Xamarin article :-

    developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/android/remote_notifications_in_android/

    It might help you too.

    Paul Diston

  • DonaldJansenDonaldJansen USMember

    I managed to get mine working by doing the following

    [Service]
    [IntentFilter(new[] { ActionNotification })]
    public class NotificationIntentService : IntentService
    {
        public const string ActionNotification = "NotificationIntentServiceAction.Action";
    
        protected override void OnHandleIntent(Intent intent)
        {
    
        }
    }
    

    And

    var intent = new Intent(Application.Context.ApplicationContext, typeof(NotificationIntentService));
    intent.SetAction(NotificationIntentService.ActionNotification);
    

    Thank you for your help it is much appreciated

Sign In or Register to comment.