Skip to content

Commit a089554

Browse files
committed
chore(demo): make Android channel ID configurable
1 parent 0e7ab0a commit a089554

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/Services/OneSignalApiService.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace OneSignalDemo.Services;
66

77
public class OneSignalApiService
88
{
9+
private const string DefaultAndroidChannelId = "b3b015d9-c050-4042-8548-dcc34aa44aa4";
10+
911
private string _appId = "";
1012

1113
public void SetAppId(string appId) => _appId = appId;
@@ -20,6 +22,12 @@ public bool HasApiKey()
2022

2123
private string GetApiKey() => DotEnv.Get("ONESIGNAL_API_KEY");
2224

25+
private static string GetAndroidChannelId()
26+
{
27+
var value = DotEnv.Get("ONESIGNAL_ANDROID_CHANNEL_ID")?.Trim();
28+
return string.IsNullOrEmpty(value) ? DefaultAndroidChannelId : value;
29+
}
30+
2331
public async Task<bool> SendNotificationAsync(NotificationType type, string subscriptionId)
2432
{
2533
try
@@ -55,7 +63,7 @@ public async Task<bool> SendNotificationAsync(NotificationType type, string subs
5563
extra = new Dictionary<string, object>
5664
{
5765
["ios_sound"] = "vine_boom.wav",
58-
["android_channel_id"] = "b3b015d9-c050-4042-8548-dcc34aa44aa4",
66+
["android_channel_id"] = GetAndroidChannelId(),
5967
};
6068
break;
6169
default:

0 commit comments

Comments
 (0)