-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Local notifications sample. * Tidy up. * Remove Windows/Tizen files.
- Loading branch information
1 parent
34397ef
commit d0eb6b2
Showing
43 changed files
with
1,436 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
8.0/PlatformIntegration/LocalNotificationsDemo/LocalNotificationsDemo.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.10.35004.147 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalNotificationsDemo", "LocalNotificationsDemo\LocalNotificationsDemo.csproj", "{919BBF23-F5F7-49D3-8FEF-A3CDB0C6CA41}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{919BBF23-F5F7-49D3-8FEF-A3CDB0C6CA41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{919BBF23-F5F7-49D3-8FEF-A3CDB0C6CA41}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{919BBF23-F5F7-49D3-8FEF-A3CDB0C6CA41}.Debug|Any CPU.Deploy.0 = Debug|Any CPU | ||
{919BBF23-F5F7-49D3-8FEF-A3CDB0C6CA41}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{919BBF23-F5F7-49D3-8FEF-A3CDB0C6CA41}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{919BBF23-F5F7-49D3-8FEF-A3CDB0C6CA41}.Release|Any CPU.Deploy.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {4A601762-D71D-43FC-A58C-DE0806605E83} | ||
EndGlobalSection | ||
EndGlobal |
14 changes: 14 additions & 0 deletions
14
8.0/PlatformIntegration/LocalNotificationsDemo/LocalNotificationsDemo/App.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version = "1.0" encoding = "UTF-8" ?> | ||
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:local="clr-namespace:LocalNotificationsDemo" | ||
x:Class="LocalNotificationsDemo.App"> | ||
<Application.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="Resources/Styles/Colors.xaml" /> | ||
<ResourceDictionary Source="Resources/Styles/Styles.xaml" /> | ||
</ResourceDictionary.MergedDictionaries> | ||
</ResourceDictionary> | ||
</Application.Resources> | ||
</Application> |
12 changes: 12 additions & 0 deletions
12
8.0/PlatformIntegration/LocalNotificationsDemo/LocalNotificationsDemo/App.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace LocalNotificationsDemo | ||
{ | ||
public partial class App : Application | ||
{ | ||
public App() | ||
{ | ||
InitializeComponent(); | ||
|
||
MainPage = new AppShell(); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
8.0/PlatformIntegration/LocalNotificationsDemo/LocalNotificationsDemo/AppShell.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<Shell | ||
x:Class="LocalNotificationsDemo.AppShell" | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:local="clr-namespace:LocalNotificationsDemo" | ||
Shell.FlyoutBehavior="Disabled" | ||
Title="Local notifications demo"> | ||
|
||
<ShellContent | ||
Title="Home" | ||
ContentTemplate="{DataTemplate local:MainPage}" | ||
Route="MainPage" /> | ||
|
||
</Shell> |
10 changes: 10 additions & 0 deletions
10
8.0/PlatformIntegration/LocalNotificationsDemo/LocalNotificationsDemo/AppShell.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace LocalNotificationsDemo | ||
{ | ||
public partial class AppShell : Shell | ||
{ | ||
public AppShell() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...mIntegration/LocalNotificationsDemo/LocalNotificationsDemo/INotificationManagerService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace LocalNotificationsDemo; | ||
|
||
public interface INotificationManagerService | ||
{ | ||
event EventHandler NotificationReceived; | ||
void SendNotification(string title, string message, DateTime? notifyTime = null); | ||
void ReceiveNotification(string title, string message); | ||
} | ||
|
59 changes: 59 additions & 0 deletions
59
...rmIntegration/LocalNotificationsDemo/LocalNotificationsDemo/LocalNotificationsDemo.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks> | ||
|
||
<!-- Note for MacCatalyst: | ||
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64. | ||
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>. | ||
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated; | ||
either BOTH runtimes must be indicated or ONLY macatalyst-x64. --> | ||
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> --> | ||
|
||
<OutputType>Exe</OutputType> | ||
<RootNamespace>LocalNotificationsDemo</RootNamespace> | ||
<UseMaui>true</UseMaui> | ||
<SingleProject>true</SingleProject> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<!-- Display name --> | ||
<ApplicationTitle>LocalNotificationsDemo</ApplicationTitle> | ||
|
||
<!-- App Identifier --> | ||
<ApplicationId>com.companyname.localnotificationsdemo</ApplicationId> | ||
|
||
<!-- Versions --> | ||
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> | ||
<ApplicationVersion>1</ApplicationVersion> | ||
|
||
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion> | ||
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion> | ||
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">23.0</SupportedOSPlatformVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<!-- App Icon --> | ||
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" /> | ||
|
||
<!-- Splash Screen --> | ||
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" /> | ||
|
||
<!-- Images --> | ||
<MauiImage Include="Resources\Images\*" /> | ||
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" /> | ||
|
||
<!-- Custom Fonts --> | ||
<MauiFont Include="Resources\Fonts\*" /> | ||
|
||
<!-- Raw Assets (also remove the "Resources\Raw" prefix) --> | ||
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" /> | ||
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
24 changes: 24 additions & 0 deletions
24
8.0/PlatformIntegration/LocalNotificationsDemo/LocalNotificationsDemo/MainPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="LocalNotificationsDemo.MainPage" | ||
Title="Local notifications" | ||
Padding="10"> | ||
<VerticalStackLayout x:Name="verticalStackLayout" | ||
Spacing="6"> | ||
<Label Text="Click the button below to create a local notification." | ||
HorizontalOptions="Center" | ||
VerticalOptions="Start" /> | ||
<Button Text="Create Notification" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Start" | ||
Clicked="OnSendClick" /> | ||
<Label Text="Click the button below to schedule a local notification for in 10 seconds time." | ||
HorizontalOptions="Center" | ||
VerticalOptions="Start" /> | ||
<Button Text="Create Notification" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Start" | ||
Clicked="OnScheduleClick" /> | ||
</VerticalStackLayout> | ||
</ContentPage> |
60 changes: 60 additions & 0 deletions
60
8.0/PlatformIntegration/LocalNotificationsDemo/LocalNotificationsDemo/MainPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#if ANDROID | ||
using LocalNotificationsDemo.Platforms.Android; | ||
#endif | ||
|
||
namespace LocalNotificationsDemo; | ||
|
||
public partial class MainPage : ContentPage | ||
{ | ||
INotificationManagerService notificationManager; | ||
int notificationNumber = 0; | ||
|
||
public MainPage(INotificationManagerService manager) | ||
{ | ||
InitializeComponent(); | ||
|
||
notificationManager = manager; | ||
notificationManager.NotificationReceived += (sender, eventArgs) => | ||
{ | ||
var eventData = (NotificationEventArgs)eventArgs; | ||
ShowNotification(eventData.Title, eventData.Message); | ||
}; | ||
} | ||
|
||
#if ANDROID | ||
protected override async void OnAppearing() | ||
{ | ||
base.OnAppearing(); | ||
|
||
PermissionStatus status = await Permissions.RequestAsync<NotificationPermission>(); | ||
} | ||
#endif | ||
|
||
void OnSendClick(object sender, EventArgs e) | ||
{ | ||
notificationNumber++; | ||
string title = $"Local Notification #{notificationNumber}"; | ||
string message = $"You have now received {notificationNumber} notifications!"; | ||
notificationManager.SendNotification(title, message); | ||
} | ||
|
||
void OnScheduleClick(object sender, EventArgs e) | ||
{ | ||
notificationNumber++; | ||
string title = $"Local Notification #{notificationNumber}"; | ||
string message = $"You have now received {notificationNumber} notifications!"; | ||
notificationManager.SendNotification(title, message, DateTime.Now.AddSeconds(10)); | ||
} | ||
|
||
void ShowNotification(string title, string message) | ||
{ | ||
MainThread.BeginInvokeOnMainThread(() => | ||
{ | ||
var msg = new Label() | ||
{ | ||
Text = $"Notification Received:\nTitle: {title}\nMessage: {message}" | ||
}; | ||
verticalStackLayout.Children.Add(msg); | ||
}); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
8.0/PlatformIntegration/LocalNotificationsDemo/LocalNotificationsDemo/MauiProgram.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace LocalNotificationsDemo | ||
{ | ||
public static class MauiProgram | ||
{ | ||
public static MauiApp CreateMauiApp() | ||
{ | ||
var builder = MauiApp.CreateBuilder(); | ||
builder | ||
.UseMauiApp<App>() | ||
.ConfigureFonts(fonts => | ||
{ | ||
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); | ||
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); | ||
}); | ||
|
||
#if DEBUG | ||
builder.Logging.AddDebug(); | ||
#endif | ||
|
||
#if ANDROID | ||
builder.Services.AddSingleton<INotificationManagerService, LocalNotificationsDemo.Platforms.Android.NotificationManagerService>(); | ||
#elif IOS | ||
builder.Services.AddSingleton<INotificationManagerService, LocalNotificationsDemo.Platforms.iOS.NotificationManagerService>(); | ||
#elif MACCATALYST | ||
builder.Services.AddSingleton<INotificationManagerService, LocalNotificationsDemo.Platforms.MacCatalyst.NotificationManagerService>(); | ||
#endif | ||
builder.Services.AddSingleton<MainPage>(); | ||
|
||
return builder.Build(); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...latformIntegration/LocalNotificationsDemo/LocalNotificationsDemo/NotificationEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace LocalNotificationsDemo; | ||
|
||
public class NotificationEventArgs : EventArgs | ||
{ | ||
public string Title { get; set; } | ||
public string Message { get; set; } | ||
} | ||
|
19 changes: 19 additions & 0 deletions
19
...tegration/LocalNotificationsDemo/LocalNotificationsDemo/Platforms/Android/AlarmHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Android.Content; | ||
|
||
namespace LocalNotificationsDemo.Platforms.Android; | ||
|
||
[BroadcastReceiver(Enabled = true, Label = "Local Notifications Broadcast Receiver")] | ||
public class AlarmHandler : BroadcastReceiver | ||
{ | ||
public override void OnReceive(Context context, Intent intent) | ||
{ | ||
if (intent?.Extras != null) | ||
{ | ||
string title = intent.GetStringExtra(NotificationManagerService.TitleKey); | ||
string message = intent.GetStringExtra(NotificationManagerService.MessageKey); | ||
|
||
NotificationManagerService manager = NotificationManagerService.Instance ?? new NotificationManagerService(); | ||
manager.Show(title, message); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ation/LocalNotificationsDemo/LocalNotificationsDemo/Platforms/Android/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> | ||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> | ||
</manifest> |
18 changes: 18 additions & 0 deletions
18
...tegration/LocalNotificationsDemo/LocalNotificationsDemo/Platforms/Android/BootReceiver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Android.App; | ||
using Android.Content; | ||
|
||
namespace LocalNotificationsDemo.Platforms.Android; | ||
|
||
[BroadcastReceiver(Enabled = true, Label = "Reboot complete receiver", Exported = false)] | ||
[IntentFilter(new[] { Intent.ActionBootCompleted })] | ||
public class BootReceiver : BroadcastReceiver | ||
{ | ||
public override void OnReceive(Context context, Intent intent) | ||
{ | ||
if (intent.Action == "android.intent.action.BOOT_COMPLETED") | ||
{ | ||
// Recreate alarms | ||
} | ||
} | ||
} | ||
|
37 changes: 37 additions & 0 deletions
37
...tegration/LocalNotificationsDemo/LocalNotificationsDemo/Platforms/Android/MainActivity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Android.App; | ||
using Android.Content; | ||
using Android.Content.PM; | ||
using Android.OS; | ||
|
||
namespace LocalNotificationsDemo | ||
{ | ||
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] | ||
public class MainActivity : MauiAppCompatActivity | ||
{ | ||
protected override void OnCreate(Bundle? savedInstanceState) | ||
{ | ||
base.OnCreate(savedInstanceState); | ||
|
||
CreateNotificationFromIntent(Intent); | ||
} | ||
|
||
protected override void OnNewIntent(Intent? intent) | ||
{ | ||
base.OnNewIntent(intent); | ||
|
||
CreateNotificationFromIntent(intent); | ||
} | ||
|
||
static void CreateNotificationFromIntent(Intent intent) | ||
{ | ||
if (intent?.Extras != null) | ||
{ | ||
string title = intent.GetStringExtra(LocalNotificationsDemo.Platforms.Android.NotificationManagerService.TitleKey); | ||
string message = intent.GetStringExtra(LocalNotificationsDemo.Platforms.Android.NotificationManagerService.MessageKey); | ||
|
||
var service = IPlatformApplication.Current?.Services.GetService<INotificationManagerService>(); | ||
service?.ReceiveNotification(title, message); | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ration/LocalNotificationsDemo/LocalNotificationsDemo/Platforms/Android/MainApplication.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Android.App; | ||
using Android.Runtime; | ||
|
||
namespace LocalNotificationsDemo | ||
{ | ||
[Application] | ||
public class MainApplication : MauiApplication | ||
{ | ||
public MainApplication(IntPtr handle, JniHandleOwnership ownership) | ||
: base(handle, ownership) | ||
{ | ||
} | ||
|
||
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); | ||
} | ||
} |
Oops, something went wrong.