From fe84fa5610c434d948d11b04eb2453e6a8fab0e1 Mon Sep 17 00:00:00 2001 From: anjalin14 Date: Tue, 5 Aug 2025 15:31:47 +0100 Subject: [PATCH 1/2] Package code sample testing --- .../Documentation~/Android.md | 18 +-------------- .../Tests/Editor/DocCodeSamples.meta | 8 +++++++ .../ManageNotificationChannels.cs | 15 +++++++++++++ .../ManageNotificationChannels.cs.meta | 2 ++ ...cations.DocCodeSamples.Editor.Tests.asmdef | 22 +++++++++++++++++++ ...ns.DocCodeSamples.Editor.Tests.asmdef.meta | 7 ++++++ 6 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 com.unity.mobile.notifications/Tests/Editor/DocCodeSamples.meta create mode 100644 com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/ManageNotificationChannels.cs create mode 100644 com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/ManageNotificationChannels.cs.meta create mode 100644 com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/Unity.com.unity.mobile.notifications.DocCodeSamples.Editor.Tests.asmdef create mode 100644 com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/Unity.com.unity.mobile.notifications.DocCodeSamples.Editor.Tests.asmdef.meta diff --git a/com.unity.mobile.notifications/Documentation~/Android.md b/com.unity.mobile.notifications/Documentation~/Android.md index 7a1abc9f..c4141bc2 100644 --- a/com.unity.mobile.notifications/Documentation~/Android.md +++ b/com.unity.mobile.notifications/Documentation~/Android.md @@ -6,23 +6,7 @@ Starting in Android 8.0, all notifications must be assigned to a notification ch Notification channels can be grouped together. This is not required, but it may look better in the Settings UI. -```c# -var group = new AndroidNotificationChannelGroup() -{ - Id = "Main", - Name = "Main notifications", -}; -AndroidNotificationCenter.RegisterNotificationChannelGroup(group); -var channel = new AndroidNotificationChannel() -{ - Id = "channel_id", - Name = "Default Channel", - Importance = Importance.Default, - Description = "Generic notifications", - Group = "Main", // must be same as Id of previously registered group -}; -AndroidNotificationCenter.RegisterNotificationChannel(channel); -``` +[!code-cs[](../Tests/Editor/DocCodeSamples/ManageNotificationChannels.cs)] For details about other properties you can set, see [AndroidNotificationChannel](../api/Unity.Notifications.Android.AndroidNotificationChannel.html). diff --git a/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples.meta b/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples.meta new file mode 100644 index 00000000..8fb246ff --- /dev/null +++ b/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2fee4dbf6ca204cd287f2bf9515a0f2d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/ManageNotificationChannels.cs b/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/ManageNotificationChannels.cs new file mode 100644 index 00000000..7738be95 --- /dev/null +++ b/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/ManageNotificationChannels.cs @@ -0,0 +1,15 @@ +var group = new AndroidNotificationChannelGroup() +{ + Id = "Main", + Name = "Main notifications", +}; +AndroidNotificationCenter.RegisterNotificationChannelGroup(group); +var channel = new AndroidNotificationChannel() +{ + Id = "channel_id", + Name = "Default Channel", + Importance = Importance.Default, + Description = "Generic notifications", + Group = "Main", // must be same as Id of previously registered group +}; +AndroidNotificationCenter.RegisterNotificationChannel(channel); \ No newline at end of file diff --git a/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/ManageNotificationChannels.cs.meta b/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/ManageNotificationChannels.cs.meta new file mode 100644 index 00000000..16cef3ab --- /dev/null +++ b/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/ManageNotificationChannels.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: ee53b1978f2f04accbb37d195d296c1c \ No newline at end of file diff --git a/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/Unity.com.unity.mobile.notifications.DocCodeSamples.Editor.Tests.asmdef b/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/Unity.com.unity.mobile.notifications.DocCodeSamples.Editor.Tests.asmdef new file mode 100644 index 00000000..f25c4d54 --- /dev/null +++ b/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/Unity.com.unity.mobile.notifications.DocCodeSamples.Editor.Tests.asmdef @@ -0,0 +1,22 @@ +{ + "name": "NewAssembly", + "rootNamespace": "", + "references": [ + "GUID:d6bcb02e32b9c47c8a8a5af0676695d5" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [ + "nunit.framework.dll" + ], + "autoReferenced": false, + "defineConstraints": [ + "UNITY_INCLUDE_TESTS" + ], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/Unity.com.unity.mobile.notifications.DocCodeSamples.Editor.Tests.asmdef.meta b/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/Unity.com.unity.mobile.notifications.DocCodeSamples.Editor.Tests.asmdef.meta new file mode 100644 index 00000000..f3906955 --- /dev/null +++ b/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/Unity.com.unity.mobile.notifications.DocCodeSamples.Editor.Tests.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: d2136e2c4670f41408aecbd4ebdbae50 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 01917220d46ca293cf14ca1832f2d17aa2714f33 Mon Sep 17 00:00:00 2001 From: anjalin14 Date: Wed, 6 Aug 2025 12:46:34 +0100 Subject: [PATCH 2/2] Update code example to embed within class --- .../ManageNotificationChannels.cs | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/ManageNotificationChannels.cs b/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/ManageNotificationChannels.cs index 7738be95..f1c54bcd 100644 --- a/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/ManageNotificationChannels.cs +++ b/com.unity.mobile.notifications/Tests/Editor/DocCodeSamples/ManageNotificationChannels.cs @@ -1,15 +1,24 @@ -var group = new AndroidNotificationChannelGroup() +using Unity.Notifications.Android; +using UnityEngine; + +public class ManageNotificationChannels: MonoBehaviour { - Id = "Main", - Name = "Main notifications", -}; -AndroidNotificationCenter.RegisterNotificationChannelGroup(group); -var channel = new AndroidNotificationChannel() -{ - Id = "channel_id", - Name = "Default Channel", - Importance = Importance.Default, - Description = "Generic notifications", - Group = "Main", // must be same as Id of previously registered group -}; -AndroidNotificationCenter.RegisterNotificationChannel(channel); \ No newline at end of file + var group = new AndroidNotificationChannelGroup() + { + Id = "Main", + Name = "Main notifications", + }; + + AndroidNotificationCenter.RegisterNotificationChannelGroup(group); + + var channel = new AndroidNotificationChannel() + { + Id = "channel_id", + Name = "Default Channel", + Importance = Importance.Default, + Description = "Generic notifications", + Group = "Main", // must be same as Id of previously registered group + }; + + AndroidNotificationCenter.RegisterNotificationChannel(channel); +} \ No newline at end of file