Search code examples
notificationsxamarin.formsalarmmanager

Schedule local notification Xamarin Forms


I have a question about local notification in Xamarin. I need to be able schedule more than one local notification in different hours.

What I mean ...

day 1
notification 1 - h 10 am - remember appointment 1
notification 2 - h 02 pm - remember appointment 2
notification 3 - h 08 pm - remember appointment 3

day 2
notification 1 - h 08 am - remember appointment 1
notification 2 - h 11 am - remember appointment 2
notification 3 - h 03 pm - remember appointment 3

I read this article but the implementation with SetInexactRepeating doesn't work in my case because the manager rememeber only one notification (example appointment 1) and not anything else.

Does Xamarin allow to create this scenario? And if yes, can anyone help me?


Solution

  • In order to have multiple alarms in Android, each one needs a unique identifier. In the article you linked to, zero is used each time. This could be your problem. See this answer for how to pass a unique identifier to the getBroadcast call (note passing _id instead of 0):

        Intent intent = new Intent(load.this, AlarmReceiver.class);
        final int _id = (int) System.currentTimeMillis();
        PendingIntent appIntent = PendingIntent.getBroadcast(this, _id, intent,PendingIntent.FLAG_ONE_SHOT);