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.

59 lines
2.4 KiB

  1. using Android.App;
  2. using Android.Content;
  3. using Android.OS;
  4. using AndroidX.Core.App;
  5. using GMCabsDriverAssistantSolution.Platforms.Android.Helpers;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. [assembly: Dependency(typeof(NotificationHelper))]
  12. namespace GMCabsDriverAssistantSolution.Platforms.Android.Helpers
  13. {
  14. internal class NotificationHelper : INotification
  15. {
  16. private static string foregroundChannelId = "9001";
  17. private static Context context = global::Android.App.Application.Context;
  18. public Notification ReturnNotif()
  19. {
  20. var intent = new Intent(context, typeof(MainActivity));
  21. intent.AddFlags(ActivityFlags.SingleTop);
  22. intent.PutExtra("Title", "Message");
  23. var pendingIntentFlags = (Build.VERSION.SdkInt >= BuildVersionCodes.S)
  24. ? PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable
  25. : PendingIntentFlags.UpdateCurrent;
  26. var pendingActivityIntent = PendingIntent.GetActivity(context, 0, intent, pendingIntentFlags);
  27. var pendingIntent = PendingIntent.GetBroadcast(context, 0, intent, pendingIntentFlags);
  28. var notifBuilder = new NotificationCompat.Builder(context, foregroundChannelId)
  29. .SetContentTitle("Location")
  30. .SetContentText("Update location")
  31. .SetOngoing(true)
  32. .SetContentIntent(pendingIntent);
  33. if (global::Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.O)
  34. {
  35. NotificationChannel notificationChannel = new NotificationChannel(foregroundChannelId, "Title", NotificationImportance.High);
  36. notificationChannel.Importance = NotificationImportance.High;
  37. notificationChannel.EnableLights(true);
  38. notificationChannel.EnableVibration(true);
  39. notificationChannel.SetShowBadge(true);
  40. notificationChannel.SetVibrationPattern(new long[] { 100, 200, 300 });
  41. var notifManager = context.GetSystemService(Context.NotificationService) as NotificationManager;
  42. if (notifManager != null)
  43. {
  44. notifBuilder.SetChannelId(foregroundChannelId);
  45. notifManager.CreateNotificationChannel(notificationChannel);
  46. }
  47. }
  48. return notifBuilder.Build();
  49. }
  50. }
  51. }