Export Option
Added export function
This commit is contained in:
@@ -158,10 +158,12 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
|
||||
requestCode,
|
||||
intent,
|
||||
BuildPendingIntentFlags());
|
||||
if (pendingIntent is null)
|
||||
return;
|
||||
|
||||
var when = triggerAt.ToUnixTimeMilliseconds();
|
||||
|
||||
if (CanUseExactAlarms(context, alarmManager))
|
||||
if (OperatingSystem.IsAndroidVersionAtLeast(23) && CanUseExactAlarms(alarmManager))
|
||||
{
|
||||
alarmManager.SetExactAndAllowWhileIdle(AlarmType.RtcWakeup, when, pendingIntent);
|
||||
return;
|
||||
@@ -203,28 +205,50 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
|
||||
|
||||
var smallIcon = context.ApplicationInfo?.Icon ?? global::Android.Resource.Drawable.IcDialogInfo;
|
||||
|
||||
var builder = new NotificationCompat.Builder(context, channelId)
|
||||
.SetSmallIcon(smallIcon)
|
||||
.SetContentTitle(title)
|
||||
.SetContentText(message)
|
||||
.SetPriority((int)NotificationPriority.High)
|
||||
.SetAutoCancel(true)
|
||||
.SetContentIntent(openPendingIntent)
|
||||
.SetOnlyAlertOnce(true)
|
||||
.AddAction(0, yellowLabel, yellowPendingIntent)
|
||||
.AddAction(0, redLabel, redPendingIntent)
|
||||
.AddAction(0, grayLabel, grayPendingIntent);
|
||||
var builder = new NotificationCompat.Builder(context, channelId);
|
||||
builder.SetSmallIcon(smallIcon);
|
||||
builder.SetContentTitle(title);
|
||||
builder.SetContentText(message);
|
||||
builder.SetPriority((int)NotificationPriority.High);
|
||||
builder.SetAutoCancel(true);
|
||||
builder.SetOnlyAlertOnce(true);
|
||||
|
||||
if (openPendingIntent is not null)
|
||||
builder.SetContentIntent(openPendingIntent);
|
||||
|
||||
if (yellowPendingIntent is not null)
|
||||
builder.AddAction(0, yellowLabel, yellowPendingIntent);
|
||||
|
||||
if (redPendingIntent is not null)
|
||||
builder.AddAction(0, redLabel, redPendingIntent);
|
||||
|
||||
if (grayPendingIntent is not null)
|
||||
builder.AddAction(0, grayLabel, grayPendingIntent);
|
||||
|
||||
if (vibrationEnabled && !OperatingSystem.IsAndroidVersionAtLeast(26))
|
||||
builder.SetVibrate(NotificationVibrationPattern);
|
||||
|
||||
NotificationManagerCompat.From(context).Notify(notificationId, builder.Build());
|
||||
var notification = builder.Build();
|
||||
if (notification is null)
|
||||
return;
|
||||
|
||||
var notificationManager = NotificationManagerCompat.From(context);
|
||||
notificationManager?.Notify(notificationId, notification);
|
||||
}
|
||||
|
||||
private static PendingIntent CreateOpenQuickEntryPendingIntent(Context context, int notificationId, string date)
|
||||
private static PendingIntent? CreateOpenQuickEntryPendingIntent(Context context, int notificationId, string date)
|
||||
{
|
||||
var launchIntent = context.PackageManager?.GetLaunchIntentForPackage(context.PackageName)
|
||||
?? new Intent(context, typeof(MainActivity));
|
||||
Intent launchIntent;
|
||||
var packageName = context.PackageName;
|
||||
if (!string.IsNullOrWhiteSpace(packageName))
|
||||
{
|
||||
launchIntent = context.PackageManager?.GetLaunchIntentForPackage(packageName)
|
||||
?? new Intent(context, typeof(MainActivity));
|
||||
}
|
||||
else
|
||||
{
|
||||
launchIntent = new Intent(context, typeof(MainActivity));
|
||||
}
|
||||
|
||||
launchIntent.SetAction(ActionOpenQuickEntry);
|
||||
launchIntent.AddFlags(ActivityFlags.SingleTop | ActivityFlags.ClearTop | ActivityFlags.NewTask);
|
||||
@@ -239,7 +263,7 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
|
||||
BuildPendingIntentFlags());
|
||||
}
|
||||
|
||||
private static PendingIntent CreateSaveStatusPendingIntent(Context context, int notificationId, string status, string date)
|
||||
private static PendingIntent? CreateSaveStatusPendingIntent(Context context, int notificationId, string status, string date)
|
||||
{
|
||||
var intent = new Intent(context, typeof(CfsNotificationReceiver));
|
||||
intent.SetAction(ActionSaveStatus);
|
||||
@@ -313,14 +337,17 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
|
||||
intent,
|
||||
BuildPendingIntentFlags());
|
||||
|
||||
alarmManager.Cancel(pendingIntent);
|
||||
NotificationManagerCompat.From(context).Cancel(BuildNotificationId(scheduleId, day));
|
||||
if (pendingIntent is not null)
|
||||
alarmManager.Cancel(pendingIntent);
|
||||
|
||||
var notificationManager = NotificationManagerCompat.From(context);
|
||||
notificationManager?.Cancel(BuildNotificationId(scheduleId, day));
|
||||
}
|
||||
|
||||
Preferences.Default.Remove(PrefScheduledIds);
|
||||
}
|
||||
|
||||
private static bool CanUseExactAlarms(Context context, AlarmManager alarmManager)
|
||||
private static bool CanUseExactAlarms(AlarmManager alarmManager)
|
||||
{
|
||||
if (!OperatingSystem.IsAndroidVersionAtLeast(31))
|
||||
return true;
|
||||
@@ -387,4 +414,4 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
|
||||
if (flags.HasFlag(NotificationWeekdays.Saturday)) yield return DayOfWeek.Saturday;
|
||||
if (flags.HasFlag(NotificationWeekdays.Sunday)) yield return DayOfWeek.Sunday;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ public sealed class CfsNotificationReceiver : BroadcastReceiver
|
||||
private void HandleSaveStatus(Context context, Intent intent)
|
||||
{
|
||||
var pendingResult = GoAsync();
|
||||
if (pendingResult is null)
|
||||
return;
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
@@ -76,7 +78,8 @@ public sealed class CfsNotificationReceiver : BroadcastReceiver
|
||||
timestamp: DateTime.Now,
|
||||
source: EntrySource.App);
|
||||
|
||||
NotificationManagerCompat.From(context).Cancel(notificationId);
|
||||
var notificationManager = NotificationManagerCompat.From(context);
|
||||
notificationManager?.Cancel(notificationId);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -117,4 +120,4 @@ public sealed class CfsNotificationReceiver : BroadcastReceiver
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user