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.

70 lines
4.1 KiB

  1. using Android.App;
  2. using Android.OS;
  3. using GMCabsDriverAssistant.Services;
  4. using GMCabsDriverAssistantSolution.Platforms.Android.Services;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using Application = Android.App.Application;
  11. [assembly: Dependency(typeof(NotificationChannelService))]
  12. namespace GMCabsDriverAssistantSolution.Platforms.Android.Services
  13. {
  14. public class NotificationChannelService : INotificationChannelService
  15. {
  16. #region Constants
  17. public const string TAG = nameof(GMCabsDriverAssistantApplication);
  18. public static string SILENT_NOTIFICATION_CHANNEL_ID = "GMCabsDriverAssistantSilentNotificationChannel";
  19. public static string SILENT_NOTIFICATION_CHANNEL_NAME = "GM Cabs Silent Notification Channel";
  20. public static string SOUND_NOTIFICATION_CHANNEL_ID = "GMCabsDriverAssistantChannel";
  21. public static string SOUND_NOTIFICATION_CHANNEL_NAME = "GM Cabs Notification Channel";
  22. public static string SYSTEM_SOUND_NOTIFICATION_CHANNEL_ID = "GMCabsDriverAssistantSystemChannel";
  23. public static string SYSTEM_SOUND_NOTIFICATION_CHANNEL_NAME = "GM Cabs System Notification Channel";
  24. #endregion
  25. public void ManageNotificationChannelService()
  26. {
  27. if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
  28. {
  29. var silentNotificationImportance = NotificationImportance.Low;
  30. var soundNotificationImportance = NotificationImportance.Max;
  31. var soundFileName = "newbooking";
  32. NotificationManager silentNotificationManager = Application.Context.GetSystemService(global::Android.Content.Context.NotificationService) as NotificationManager;
  33. NotificationManager customNotificationManager = Application.Context.GetSystemService(global::Android.Content.Context.NotificationService) as NotificationManager;
  34. NotificationManager systemNotificationManager = Application.Context.GetSystemService(global::Android.Content.Context.NotificationService) as NotificationManager;
  35. /* Delete Notification Channel */
  36. silentNotificationManager.DeleteNotificationChannel(SILENT_NOTIFICATION_CHANNEL_ID);
  37. customNotificationManager.DeleteNotificationChannel(SOUND_NOTIFICATION_CHANNEL_ID);
  38. systemNotificationManager.DeleteNotificationChannel(SYSTEM_SOUND_NOTIFICATION_CHANNEL_ID);
  39. /* Silent Notification Channel */
  40. NotificationChannel silentNotificationchannel = new NotificationChannel(SILENT_NOTIFICATION_CHANNEL_ID, SILENT_NOTIFICATION_CHANNEL_NAME, silentNotificationImportance);
  41. silentNotificationchannel.EnableVibration(true);
  42. silentNotificationchannel.LockscreenVisibility = NotificationVisibility.Public;
  43. silentNotificationManager.CreateNotificationChannel(silentNotificationchannel);
  44. /* Custom Sound Notification Channel */
  45. NotificationChannel soundNotificationChannel = new NotificationChannel(SOUND_NOTIFICATION_CHANNEL_ID, SOUND_NOTIFICATION_CHANNEL_NAME, soundNotificationImportance);
  46. soundNotificationChannel.EnableVibration(true);
  47. soundNotificationChannel.LockscreenVisibility = NotificationVisibility.Public;
  48. soundNotificationChannel.SetSound(global::Android.Net.Uri.Parse("android.resource://au.com.gmcabs.driverassistant/raw/" + soundFileName), null);
  49. customNotificationManager.CreateNotificationChannel(soundNotificationChannel);
  50. /* System Sound Notification Channel */
  51. NotificationChannel systemSoundNotificationChannel = new NotificationChannel(SYSTEM_SOUND_NOTIFICATION_CHANNEL_ID, SYSTEM_SOUND_NOTIFICATION_CHANNEL_NAME, soundNotificationImportance);
  52. systemSoundNotificationChannel.EnableVibration(true);
  53. systemSoundNotificationChannel.LockscreenVisibility = NotificationVisibility.Public;
  54. systemNotificationManager.CreateNotificationChannel(systemSoundNotificationChannel);
  55. }
  56. }
  57. }
  58. }