Skip to content

Commit b3c0c3c

Browse files
committed
fix(demo): make Android channel ID configurable
1 parent 96b8e5b commit b3c0c3c

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

examples/demo/.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
ONESIGNAL_APP_ID=your-onesignal-app-id
33
ONESIGNAL_API_KEY=your_rest_api_key
44
E2E_MODE=false
5+
6+
# Optional: Android Notification Channel ID for the WITH SOUND test notification.
7+
# Create one in your OneSignal dashboard under Settings > Android Notification Categories.
8+
ONESIGNAL_ANDROID_CHANNEL_ID=

examples/demo/Assets/Scripts/Services/OneSignalApiService.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class OneSignalApiService
1616

1717
private const string PlaceholderApiKey = "your_rest_api_key";
1818

19+
private const string DefaultAndroidChannelId = "b3b015d9-c050-4042-8548-dcc34aa44aa4";
20+
1921
public void SetAppId(string appId) => _appId = appId;
2022

2123
public string GetAppId() => _appId;
@@ -28,6 +30,12 @@ public bool HasApiKey()
2830

2931
private static string GetApiKey() => DotEnv.Get("ONESIGNAL_API_KEY");
3032

33+
private static string GetAndroidChannelId()
34+
{
35+
var value = DotEnv.Get("ONESIGNAL_ANDROID_CHANNEL_ID")?.Trim();
36+
return string.IsNullOrEmpty(value) ? DefaultAndroidChannelId : value;
37+
}
38+
3139
public async Task<bool> SendNotification(NotificationType type, string subscriptionId)
3240
{
3341
if (string.IsNullOrEmpty(subscriptionId) || string.IsNullOrEmpty(_appId))
@@ -59,7 +67,7 @@ public async Task<bool> SendNotification(NotificationType type, string subscript
5967
extra = new JObject
6068
{
6169
["ios_sound"] = "vine_boom.wav",
62-
["android_channel_id"] = "b3b015d9-c050-4042-8548-dcc34aa44aa4",
70+
["android_channel_id"] = GetAndroidChannelId(),
6371
};
6472
break;
6573
default:

0 commit comments

Comments
 (0)