Skip to content

Commit fd534e7

Browse files
authored
Merge pull request #360 from hemantbeast/master
Android: Fix default notification light & sound for oreo and above
2 parents fd9d2c4 + 3137654 commit fd534e7

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

Plugin.FirebasePushNotification/FirebasePushNotificationManager.android.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
using Android.App;
1313
using Android.Content.PM;
1414
using Android.Graphics;
15+
using Android.Media;
16+
using Android.Runtime;
1517
using System.Threading.Tasks;
1618
using Java.Interop;
1719

@@ -175,8 +177,18 @@ public static void Initialize(Context context, bool resetToken, bool createDefau
175177
var channelName = DefaultNotificationChannelName;
176178
var notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
177179

178-
notificationManager.CreateNotificationChannel(new NotificationChannel(channelId,
179-
channelName, DefaultNotificationChannelImportance));
180+
Android.Net.Uri defaultSoundUri = SoundUri != null ? SoundUri : RingtoneManager.GetDefaultUri(RingtoneType.Notification);
181+
AudioAttributes attributes = new AudioAttributes.Builder()
182+
.SetUsage(AudioUsageKind.Notification)
183+
.SetContentType(AudioContentType.Sonification)
184+
.SetLegacyStreamType(Stream.Notification)
185+
.Build();
186+
187+
NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, DefaultNotificationChannelImportance);
188+
notificationChannel.EnableLights(true);
189+
notificationChannel.SetSound(defaultSoundUri, attributes);
190+
191+
notificationManager.CreateNotificationChannel(notificationChannel);
180192
}
181193

182194
System.Diagnostics.Debug.WriteLine(CrossFirebasePushNotification.Current.Token);

0 commit comments

Comments
 (0)