From 3ff89ffd8871a1f6149ddbb0949a187bf02da773 Mon Sep 17 00:00:00 2001 From: Thomas Mijieux Date: Sat, 2 Dec 2023 00:51:12 +0100 Subject: [PATCH 1/2] add reference to AndroidX in android binding project This permits to use the remoteNotificationReceived mechanism in xamarin to be able to customize notification behavior and display when the app is swiped The reference to androidx is required in order to bring in some androidx types that were missing and prevented the generation of some API --- .../OneSignal.Android.Binding.csproj | 7 +++++-- .../Transforms/EnumFields.xml | 2 +- .../NotificationExtensionAttribute.cs | 17 +++++++++++++++++ .../OneSignalSDK.Xamarin.Android.csproj | 5 +++-- .../OneSignalApp.Sample.Droid.csproj | 4 ++-- 5 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 OneSignalSDK.Xamarin.Android/NotificationExtensionAttribute.cs diff --git a/OneSignal.Android.Binding/OneSignal.Android.Binding.csproj b/OneSignal.Android.Binding/OneSignal.Android.Binding.csproj index a4f7bc65..fb0821e9 100644 --- a/OneSignal.Android.Binding/OneSignal.Android.Binding.csproj +++ b/OneSignal.Android.Binding/OneSignal.Android.Binding.csproj @@ -10,7 +10,7 @@ Resources Assets OneSignal.Android.Binding - v11.0 + v12.0 28.0.3 class-parse @@ -55,5 +55,8 @@ + + + - \ No newline at end of file + diff --git a/OneSignal.Android.Binding/Transforms/EnumFields.xml b/OneSignal.Android.Binding/Transforms/EnumFields.xml index e9af0eeb..4b78e6e7 100755 --- a/OneSignal.Android.Binding/Transforms/EnumFields.xml +++ b/OneSignal.Android.Binding/Transforms/EnumFields.xml @@ -4,7 +4,7 @@ and Fragment_tag from android.support.v4.app.FragmentActivity.FragmentTag to an enum called Android.Support.V4.App.FragmentTagType with values Id, Name, and Tag. - + diff --git a/OneSignalSDK.Xamarin.Android/NotificationExtensionAttribute.cs b/OneSignalSDK.Xamarin.Android/NotificationExtensionAttribute.cs new file mode 100644 index 00000000..796d05cf --- /dev/null +++ b/OneSignalSDK.Xamarin.Android/NotificationExtensionAttribute.cs @@ -0,0 +1,17 @@ +using System; +using System.Diagnostics; +using Android.App; +using Android.Content; + +namespace Com.OneSignal.Android +{ + [Serializable] + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + public sealed class NotificationExtensionAttribute : Attribute, Java.Interop.IJniNameProviderAttribute + { + public string Name { get; set; } + public NotificationExtensionAttribute() + { + } + } +} diff --git a/OneSignalSDK.Xamarin.Android/OneSignalSDK.Xamarin.Android.csproj b/OneSignalSDK.Xamarin.Android/OneSignalSDK.Xamarin.Android.csproj index 4c6cfe02..05da5b1c 100644 --- a/OneSignalSDK.Xamarin.Android/OneSignalSDK.Xamarin.Android.csproj +++ b/OneSignalSDK.Xamarin.Android/OneSignalSDK.Xamarin.Android.csproj @@ -11,7 +11,7 @@ Library OneSignalSDK.Xamarin OneSignalSDK.Xamarin - v11.0 + v12.0 Resources Assets @@ -284,6 +284,7 @@ + @@ -371,4 +372,4 @@ - \ No newline at end of file + diff --git a/Samples/OneSignalApp.Sample.Droid/OneSignalApp.Sample.Droid.csproj b/Samples/OneSignalApp.Sample.Droid/OneSignalApp.Sample.Droid.csproj index cb525f8c..38cdbfea 100644 --- a/Samples/OneSignalApp.Sample.Droid/OneSignalApp.Sample.Droid.csproj +++ b/Samples/OneSignalApp.Sample.Droid/OneSignalApp.Sample.Droid.csproj @@ -10,7 +10,7 @@ Library OneSignalApp.Sample.Droid OneSignalApp.Sample.Droid - v11.0 + v12.0 True Resources\Resource.designer.cs Resource @@ -392,4 +392,4 @@ - \ No newline at end of file + From bbc066a14573058ffd9b83eeae5812e116e3c635 Mon Sep 17 00:00:00 2001 From: Thomas Mijieux Date: Tue, 5 Dec 2023 17:00:25 +0100 Subject: [PATCH 2/2] add abstract base class for simple usage --- .../Additions/NotificationExtenderBase.cs | 9 +++++++++ .../Additions/OSRemoteNotificationReceivedBase.cs | 9 +++++++++ .../OneSignal.Android.Binding.csproj | 3 +++ 3 files changed, 21 insertions(+) create mode 100644 OneSignal.Android.Binding/Additions/NotificationExtenderBase.cs create mode 100644 OneSignal.Android.Binding/Additions/OSRemoteNotificationReceivedBase.cs diff --git a/OneSignal.Android.Binding/Additions/NotificationExtenderBase.cs b/OneSignal.Android.Binding/Additions/NotificationExtenderBase.cs new file mode 100644 index 00000000..c62b53a6 --- /dev/null +++ b/OneSignal.Android.Binding/Additions/NotificationExtenderBase.cs @@ -0,0 +1,9 @@ +using AndroidX.Core.App; + +namespace Com.OneSignal.Android +{ + public abstract class NotificationExtenderBase : Java.Lang.Object, NotificationCompat.IExtender + { + public abstract NotificationCompat.Builder Extend(NotificationCompat.Builder builder); + } +} diff --git a/OneSignal.Android.Binding/Additions/OSRemoteNotificationReceivedBase.cs b/OneSignal.Android.Binding/Additions/OSRemoteNotificationReceivedBase.cs new file mode 100644 index 00000000..b4bcda6b --- /dev/null +++ b/OneSignal.Android.Binding/Additions/OSRemoteNotificationReceivedBase.cs @@ -0,0 +1,9 @@ +using Android.Content; + +namespace Com.OneSignal.Android +{ + public abstract class OSRemoteNotificationReceivedBase : Java.Lang.Object, OneSignal.IOSRemoteNotificationReceivedHandler + { + public abstract void RemoteNotificationReceived(Context ctx, OSNotificationReceivedEvent ev); + } +} diff --git a/OneSignal.Android.Binding/OneSignal.Android.Binding.csproj b/OneSignal.Android.Binding/OneSignal.Android.Binding.csproj index fb0821e9..a0715137 100644 --- a/OneSignal.Android.Binding/OneSignal.Android.Binding.csproj +++ b/OneSignal.Android.Binding/OneSignal.Android.Binding.csproj @@ -43,6 +43,9 @@ + + +