From 77df392cb522037ae26fdfbdf57663df632b7bee Mon Sep 17 00:00:00 2001 From: Ali Moussa Date: Tue, 26 Mar 2019 13:00:36 +1100 Subject: [PATCH] Create a broadcast pending intent instead of service intent --- .../LocalNotifications.cs | 4 +- .../NotificationBuilder.cs | 6 +- .../Plugin.LocalNotifications.Android.csproj | 57 +- .../Resources/Resource.Designer.cs | 501 +++++++++++++++++- .../packages.config | 11 +- 5 files changed, 570 insertions(+), 9 deletions(-) diff --git a/src/Plugin.LocalNotifications.Android/LocalNotifications.cs b/src/Plugin.LocalNotifications.Android/LocalNotifications.cs index 101e0e4..777e857 100644 --- a/src/Plugin.LocalNotifications.Android/LocalNotifications.cs +++ b/src/Plugin.LocalNotifications.Android/LocalNotifications.cs @@ -55,7 +55,7 @@ public void Cancel(int id) public static void Initialize(Type notificationActivityType, Type notificationServiceType, int notificationIconId) { NotificationActivityType = notificationActivityType; - NotificationServiceType = notificationServiceType; + NotificationBroadcastReceiverType = notificationServiceType; NotificationIconId = notificationIconId; } @@ -98,7 +98,7 @@ private static ILocalNotificationActionRegistrar NewActionRegistrar(string id) } internal static Type NotificationActivityType { get; set; } - internal static Type NotificationServiceType { get; set; } + internal static Type NotificationBroadcastReceiverType { get; set; } internal static int NotificationIconId { get; set; } } } \ No newline at end of file diff --git a/src/Plugin.LocalNotifications.Android/NotificationBuilder.cs b/src/Plugin.LocalNotifications.Android/NotificationBuilder.cs index 96a1d7a..bfe2870 100644 --- a/src/Plugin.LocalNotifications.Android/NotificationBuilder.cs +++ b/src/Plugin.LocalNotifications.Android/NotificationBuilder.cs @@ -101,7 +101,7 @@ public static void Notify(LocalNotification notification) var dismissAction = notification.Actions.FirstOrDefault(a => a.ActionId == ActionIdentifiers.Dismiss); if (dismissAction != null) { - builder.SetDeleteIntent(CreatePendingIntent(notification.Id, dismissAction, ActionIdentifiers.Dismiss, LocalNotifications.NotificationServiceType)); + builder.SetDeleteIntent(CreatePendingIntent(notification.Id, dismissAction, ActionIdentifiers.Dismiss, LocalNotifications.NotificationBroadcastReceiverType)); } // User actions @@ -128,7 +128,7 @@ public static void Notify(LocalNotification notification) { foreach (var action in actions) { - var pendingIntent = CreatePendingIntent(notificationId, action, ActionIdentifiers.Action, LocalNotifications.NotificationServiceType); + var pendingIntent = CreatePendingIntent(notificationId, action, ActionIdentifiers.Action, LocalNotifications.NotificationBroadcastReceiverType); var iconId = action.IconId == 0 ? Resource.Drawable.plugin_lc_smallicon : action.IconId; yield return new Notification.Action(iconId, action.Title, pendingIntent); @@ -144,7 +144,7 @@ private static PendingIntent CreateActivityPendingIntent(int notificationId, Loc private static PendingIntent CreatePendingIntent(int notificationId, LocalNotificationAction action, string actionType, Type classType) { var intent = CreateIntent(notificationId, action, actionType, classType); - return PendingIntent.GetService(Application.Context, GetRandomId(), intent, PendingIntentFlags.UpdateCurrent); + return PendingIntent.GetBroadcast(Application.Context, GetRandomId(), intent, PendingIntentFlags.UpdateCurrent); } private static Intent CreateIntent(int notificationId, LocalNotificationAction notificationAction, string action, Type classType = null) diff --git a/src/Plugin.LocalNotifications.Android/Plugin.LocalNotifications.Android.csproj b/src/Plugin.LocalNotifications.Android/Plugin.LocalNotifications.Android.csproj index 1f0d7b2..3b071fb 100644 --- a/src/Plugin.LocalNotifications.Android/Plugin.LocalNotifications.Android.csproj +++ b/src/Plugin.LocalNotifications.Android/Plugin.LocalNotifications.Android.csproj @@ -17,6 +17,8 @@ v8.1 + + true @@ -43,9 +45,35 @@ + + ..\packages\Xamarin.Android.Arch.Core.Common.1.0.0.1\lib\MonoAndroid80\Xamarin.Android.Arch.Core.Common.dll + + + ..\packages\Xamarin.Android.Arch.Lifecycle.Common.1.0.3.1\lib\MonoAndroid80\Xamarin.Android.Arch.Lifecycle.Common.dll + + + ..\packages\Xamarin.Android.Arch.Lifecycle.Runtime.1.0.3.1\lib\MonoAndroid80\Xamarin.Android.Arch.Lifecycle.Runtime.dll + + + ..\packages\Xamarin.Android.Support.Annotations.27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Annotations.dll + + + ..\packages\Xamarin.Android.Support.Compat.27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Compat.dll + + + ..\packages\Xamarin.Android.Support.Core.UI.27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Core.UI.dll + + + ..\packages\Xamarin.Android.Support.Core.Utils.27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Core.Utils.dll + + + ..\packages\Xamarin.Android.Support.Fragment.27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Fragment.dll + + + ..\packages\Xamarin.Android.Support.Media.Compat.27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Media.Compat.dll + - ..\packages\Xamarin.Android.Support.v4.23.0.1.3\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll - True + ..\packages\Xamarin.Android.Support.v4.27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.v4.dll @@ -103,6 +131,31 @@ + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + + + + + + + + + + +