Local Notification not displayed when app is closed

DeepakDeepsDeepakDeeps INMember ✭✭✭

I am using local notification with alarm manager in Xamarin Android, it works fine and when the application was closed notification not displayed.i want to run in background also.

Please help me to resolve this..
Thanks in Advance.

Answers

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    You can try Xam.Plugins.Notifier plugin.

    Display a local notification immediately

    CrossLocalNotifications.Current.Show("title", "body");
    

    Display a local notification at a scheduled date/time

    CrossLocalNotifications.Current.Show("title", "body", 101, DateTime.Now.AddSeconds(5));
    

    Cancel a local notification

    CrossLocalNotifications.Current.Cancel(101);
    

    Check the link: https://github.com/edsnider/LocalNotificationsPlugin

  • AnandmauryaAnandmaurya INMember ✭✭
    edited June 19

    @DeepakDeeps Alarm Manager will not work in Android Oreo 8.0 and higher version. You need to use Job Scheduler to achieve your problem.

    https://developer.android.com/about/versions/oreo/background.html#broadcasts#broadcasts

    And if you are running in lower version So, Doze is particularly likely to affect activities that AlarmManager alarms and timers manage, because alarms in Android 5.1 (API level 22) or lower do not fire when the system is in Doze.

    To help with scheduling alarms, Android 6.0 (API level 23) introduces two new AlarmManager methods: setAndAllowWhileIdle() and setExactAndAllowWhileIdle(). With these methods, you can set alarms that will fire even if the device is in Doze.

    Note: Neither setAndAllowWhileIdle() nor setExactAndAllowWhileIdle() can fire alarms more than once per 9 minutes, per app.

  • RajeshAngappaRajeshAngappa INMember ✭✭

    @DeepakDeeps Please refer the below sample. Whenever app is killed it will give the notification.

    https://github.com/rajeshangappan/XamSamples/tree/master/LocalNotificationPOC

Sign In or Register to comment.