40 lines
1.5 KiB
C#
40 lines
1.5 KiB
C#
using System;
|
|
using Android.App;
|
|
using Android.Content;
|
|
|
|
namespace gehGassi.LocalNotifications.Platforms
|
|
{
|
|
/// <summary>
|
|
/// Wird automatisch in AndroidManifest.xml generiert
|
|
/// Ref : https://stackoverflow.com/questions/37379170/broadcast-receiver-onreceive-not-being-called-in-xamarin-android
|
|
/// </summary>
|
|
[BroadcastReceiver(Exported = true)]
|
|
[IntentFilter(new[] { "android.intent.action.BOOT_COMPLETED", "android.intent.action.MY_PACKAGE_REPLACED" })]
|
|
public class ScheduledNotificationBootReceiver : BroadcastReceiver
|
|
{
|
|
public override async void OnReceive(Context context, Intent intent)
|
|
{
|
|
try
|
|
{
|
|
Console.WriteLine("class ScheduledNotificationBootReceiver");
|
|
string action = intent.Action;
|
|
if (action != null)
|
|
{
|
|
if (action.Equals(Intent.ActionBootCompleted) || action.Equals(Intent.ActionMyPackageReplaced))
|
|
{
|
|
Console.WriteLine("Reschedule");
|
|
var notificationService = GetDefaultNotificationService();
|
|
await notificationService.RescheduleNotificationsAsync(context);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("Error in ScheduledNotificationBootReceiver : " + ex);
|
|
}
|
|
}
|
|
|
|
public NotificationService GetDefaultNotificationService() => new NotificationService();
|
|
}
|
|
}
|