Skip to content

Commit 1c6b91a

Browse files
Add notification handler.
1 parent e1297c6 commit 1c6b91a

20 files changed

+1978
-1721
lines changed

sample/Sample.Android/MainApplication.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public override void OnCreate()
3333
}
3434

3535
#if DEBUG
36-
NotifoFirebasePlugin.Initialize(this, new NotifoStartup(), resetToken: true);
36+
NotifoFirebasePlugin.Initialize(this, new NotifoStartup(), new NotificationHandler(), resetToken: true);
3737
#else
38-
NotifoFirebasePlugin.Initialize(this, new NotifoStartup(), resetToken: false);
38+
NotifoFirebasePlugin.Initialize(this, new NotifoStartup(), new NotificationHandler(), resetToken: false);
3939
#endif
4040
}
4141
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// ==========================================================================
2+
// Notifo.io
3+
// ==========================================================================
4+
// Copyright (c) Sebastian Stehle
5+
// All rights reserved. Licensed under the MIT license.
6+
// ==========================================================================
7+
8+
using Android.App;
9+
using Android.Content;
10+
using Android.OS;
11+
using Android.Support.V4.App;
12+
using Notifo.SDK;
13+
14+
namespace Sample.Droid
15+
{
16+
public class NotificationHandler : INotificationHandler
17+
{
18+
public void OnBuildNotification(NotificationCompat.Builder notificationBuilder, NotificationDto notification)
19+
{
20+
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
21+
{
22+
return;
23+
}
24+
25+
var soundUri = Android.Net.Uri.Parse($"{ContentResolver.SchemeAndroidResource}://{Application.Context.PackageName}/raw/announcement");
26+
27+
notificationBuilder.SetSound(soundUri);
28+
}
29+
}
30+
}

sample/Sample.Android/Resources/Resource.designer.cs

Lines changed: 1732 additions & 1654 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

sample/Sample.Android/Sample.Android.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<ItemGroup>
9494
<Compile Include="MainActivity.cs" />
9595
<Compile Include="MainApplication.cs" />
96+
<Compile Include="NotificationHandler.cs" />
9697
<Compile Include="Resources\Resource.designer.cs" />
9798
<Compile Include="Properties\AssemblyInfo.cs" />
9899
</ItemGroup>
@@ -137,6 +138,9 @@
137138
<Name>Sample</Name>
138139
</ProjectReference>
139140
</ItemGroup>
141+
<ItemGroup>
142+
<AndroidResource Include="Resources\raw\announcement.mp3" />
143+
</ItemGroup>
140144
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
141145
<ProjectExtensions>
142146
<VisualStudio>

sample/Sample.iOS/AppDelegate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary
2525
global::Xamarin.Forms.Forms.Init();
2626
LoadApplication(new App(new iOSInitializer()));
2727

28-
NotifoFirebasePlugin.Initialize(launchOptions, new NotifoStartup(), true);
28+
NotifoFirebasePlugin.Initialize(launchOptions, new NotifoStartup(), new NotificationHandler(), true);
2929
UNUserNotificationCenter.Current.Delegate = this;
3030

3131
return base.FinishedLaunching(uiApplication, launchOptions);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// ==========================================================================
2+
// Notifo.io
3+
// ==========================================================================
4+
// Copyright (c) Sebastian Stehle
5+
// All rights reserved. Licensed under the MIT license.
6+
// ==========================================================================
7+
8+
using Notifo.SDK;
9+
using UserNotifications;
10+
11+
#pragma warning disable SA1300 // Element should begin with upper-case letter
12+
namespace Sample.iOS
13+
#pragma warning restore SA1300 // Element should begin with upper-case letter
14+
{
15+
public class NotificationHandler : INotificationHandler
16+
{
17+
public void OnBuildNotification(UNMutableNotificationContent content, NotificationDto notification)
18+
{
19+
content.Sound = UNNotificationSound.GetSound("announcement.caf");
20+
}
21+
}
22+
}
657 KB
Binary file not shown.

sample/Sample.iOS/Sample.iOS.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<MtouchLink>None</MtouchLink>
5353
<MtouchInterpreter>-all</MtouchInterpreter>
5454
<CodesignProvision>
55-
</CodesignProvision>
55+
</CodesignProvision>
5656
</PropertyGroup>
5757
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
5858
<DebugType>none</DebugType>
@@ -76,7 +76,9 @@
7676
<BundleResource Include="GoogleService-Info.plist" />
7777
<None Include="Info.plist" />
7878
<Compile Include="Application.cs" />
79+
<Compile Include="NotificationHandler.cs" />
7980
<Compile Include="Properties\AssemblyInfo.cs" />
81+
<BundleResource Include="Resources\announcement.caf" />
8082
</ItemGroup>
8183
<ItemGroup>
8284
<InterfaceDefinition Include="Resources\LaunchScreen.storyboard" />

sdk/Notifo.SDK.FirebasePlugin/NotifoFirebasePlugin.android.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ public class NotifoFirebasePlugin
2121
/// </summary>
2222
/// <param name="context">The current application context.</param>
2323
/// <param name="notifoStartup">The <see cref="INotifoStartup"/> implementation.</param>
24+
/// <param name="notificationHandler">The <see cref="INotificationHandler"/> implementation.</param>
2425
/// <param name="resetToken">Set to <see langword="true"/> while debugging.</param>
2526
/// <param name="autoRegistration">Automatically register for push notifications.</param>
26-
public static void Initialize(Context context, INotifoStartup notifoStartup, bool resetToken, bool autoRegistration = true)
27+
public static void Initialize(Context context, INotifoStartup notifoStartup, INotificationHandler? notificationHandler = null, bool resetToken = false, bool autoRegistration = true)
2728
{
2829
FirebasePushNotificationManager.Initialize(context, new NotifoPushNotificationHandler(), resetToken, createDefaultNotificationChannel: true, autoRegistration);
30+
31+
NotifoIO.Current.SetNotificationHandler(notificationHandler);
2932
notifoStartup.ConfigureService(NotifoIO.Current);
3033
}
3134

0 commit comments

Comments
 (0)