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.
 
 
 
 

57 lines
2.2 KiB

  1. using Android;
  2. using Android.App;
  3. using Android.Content;
  4. using Android.Content.PM;
  5. using Android.OS;
  6. using AndroidX.Core.App;
  7. using AndroidX.Core.Content;
  8. namespace HybridApp
  9. {
  10. [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
  11. public class MainActivity : MauiAppCompatActivity
  12. {
  13. internal static readonly string Channel_ID = "TestChannel";
  14. internal static readonly int NotificationID = 101;
  15. protected override void OnCreate(Bundle savedInstanceState)
  16. {
  17. base.OnCreate(savedInstanceState);
  18. if (ContextCompat.CheckSelfPermission(this, Android.Manifest.Permission.PostNotifications) == Permission.Denied)
  19. {
  20. ActivityCompat.RequestPermissions(this, new String[] { Android.Manifest.Permission.PostNotifications }, 1);
  21. }
  22. CreateNotificationChannel();
  23. }
  24. protected override void OnNewIntent(Intent intent)
  25. {
  26. base.OnNewIntent(intent);
  27. if (intent.Extras != null)
  28. {
  29. foreach (var key in intent.Extras.KeySet())
  30. {
  31. if (key == "NavigationID")
  32. {
  33. string idValue = intent.Extras.GetString(key);
  34. if (Preferences.ContainsKey("NavigationID"))
  35. Preferences.Remove("NavigationID");
  36. Preferences.Set("NavigationID", idValue);
  37. }
  38. }
  39. }
  40. }
  41. private void CreateNotificationChannel()
  42. {
  43. if (OperatingSystem.IsOSPlatformVersionAtLeast("android", 26))
  44. {
  45. var channel = new NotificationChannel(Channel_ID, "Test Notification Channel", NotificationImportance.Default);
  46. var notificationManager = (NotificationManager)GetSystemService(Android.Content.Context.NotificationService);
  47. notificationManager.CreateNotificationChannel(channel);
  48. }
  49. }
  50. }
  51. }