Search code examples
xamarinxamarin.formsxamarin.androidfirebase-cloud-messagingazure-notificationhub

How to get notified even when app is closed using Xamarin Forms?


I'm a new developer to Xamarin Forms and I want to notify my user even when the app is closed as other apps do.

I have a web app where they can send notifications (like a campaign) to all the users registered to this campaign. My web app connects to Azure Notifications Hub which connects to Firabase Cloud Messaging. Everything works fine most of the time.

If my application is running, the notifications appear:

enter image description here

If I go to the main screen (but app is still running) it works.

enter image description here

enter image description here

When I completely close the app, the notifications stop. I need to notify my users even if they completely close the app.

How can I do this?


Solution

  • Use the plugin localnotificationsplugin.

    With it, you can schedule a notification.

    Like this:

    CrossLocalNotifications.Current.Show(“Testing notifications”, “Message text”, 1, DateTime.Now.AddDays(1));
    

    Reference in portuguese-BR (If you are brazilian) here:

    https://medium.com/@bertuzzi/meu-plugin-minha-vida-notificações-locais-a4bcd9fa1594