You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.6 KiB

1 year ago
  1. using Android.App;
  2. using Android.Content;
  3. using Android.Content.PM;
  4. using Android.OS;
  5. using Plugin.Firebase.CloudMessaging;
  6. namespace firebase;
  7. [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
  8. public class MainActivity : MauiAppCompatActivity
  9. {
  10. protected override void OnCreate(Bundle savedInstanceState)
  11. {
  12. base.OnCreate(savedInstanceState);
  13. HandleIntent(Intent);
  14. CreateNotificationChannelIfNeeded();
  15. }
  16. protected override void OnNewIntent(Intent intent)
  17. {
  18. base.OnNewIntent(intent);
  19. HandleIntent(intent);
  20. }
  21. private static void HandleIntent(Intent intent)
  22. {
  23. FirebaseCloudMessagingImplementation.OnNewIntent(intent);
  24. }
  25. private void CreateNotificationChannelIfNeeded()
  26. {
  27. if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
  28. {
  29. CreateNotificationChannel();
  30. }
  31. }
  32. private void CreateNotificationChannel()
  33. {
  34. var channelId = $"{PackageName}.general";
  35. var notificationManager = (NotificationManager)GetSystemService(NotificationService);
  36. var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default);
  37. notificationManager.CreateNotificationChannel(channel);
  38. FirebaseCloudMessagingImplementation.ChannelId = channelId;
  39. //FirebaseCloudMessagingImplementation.SmallIconRef = Resource.Drawable.ic_push_small;
  40. }
  41. }