Created
September 11, 2022 17:45
-
-
Save andreas-nesheim/e841ce184540c8e6404996dad3f06213 to your computer and use it in GitHub Desktop.
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
using Android.App; | |
using Android.Content; | |
using Android.Content.PM; | |
using Android.OS; | |
using Plugin.Firebase.CloudMessaging; | |
namespace MauiFirebasePush; | |
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, 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); | |
HandleIntent(Intent); | |
CreateNotificationChannelIfNeeded(); | |
} | |
protected override void OnNewIntent(Intent intent) | |
{ | |
base.OnNewIntent(intent); | |
HandleIntent(intent); | |
} | |
private static void HandleIntent(Intent intent) | |
{ | |
FirebaseCloudMessagingImplementation.OnNewIntent(intent); | |
} | |
private void CreateNotificationChannelIfNeeded() | |
{ | |
if (Build.VERSION.SdkInt >= BuildVersionCodes.O) | |
{ | |
CreateNotificationChannel(); | |
} | |
} | |
private void CreateNotificationChannel() | |
{ | |
var channelId = $"{PackageName}.general"; | |
var notificationManager = (NotificationManager)GetSystemService(NotificationService); | |
var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default); | |
notificationManager.CreateNotificationChannel(channel); | |
FirebaseCloudMessagingImplementation.ChannelId = channelId; | |
//FirebaseCloudMessagingImplementation.SmallIconRef = Resource.Drawable.ic_push_small; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment