Browse Source

notification helpers

master
Kaustav Chaudhuri 1 year ago
parent
commit
fe26fea450
2 changed files with 73 additions and 0 deletions
  1. +14
    -0
      GMCabsDriverAssistantSolution/Platforms/Android/Helpers/INotification.cs
  2. +59
    -0
      GMCabsDriverAssistantSolution/Platforms/Android/Helpers/NotificationHelper.cs

+ 14
- 0
GMCabsDriverAssistantSolution/Platforms/Android/Helpers/INotification.cs View File

@ -0,0 +1,14 @@
using Android.App;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GMCabsDriverAssistantSolution.Platforms.Android.Helpers
{
public interface INotification
{
Notification ReturnNotif();
}
}

+ 59
- 0
GMCabsDriverAssistantSolution/Platforms/Android/Helpers/NotificationHelper.cs View File

@ -0,0 +1,59 @@
using Android.App;
using Android.Content;
using Android.OS;
using AndroidX.Core.App;
using GMCabsDriverAssistantSolution.Platforms.Android.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
[assembly: Dependency(typeof(NotificationHelper))]
namespace GMCabsDriverAssistantSolution.Platforms.Android.Helpers
{
internal class NotificationHelper : INotification
{
private static string foregroundChannelId = "9001";
private static Context context = global::Android.App.Application.Context;
public Notification ReturnNotif()
{
var intent = new Intent(context, typeof(MainActivity));
intent.AddFlags(ActivityFlags.SingleTop);
intent.PutExtra("Title", "Message");
var pendingIntentFlags = (Build.VERSION.SdkInt >= BuildVersionCodes.S)
? PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable
: PendingIntentFlags.UpdateCurrent;
var pendingActivityIntent = PendingIntent.GetActivity(context, 0, intent, pendingIntentFlags);
var pendingIntent = PendingIntent.GetBroadcast(context, 0, intent, pendingIntentFlags);
var notifBuilder = new NotificationCompat.Builder(context, foregroundChannelId)
.SetContentTitle("Location")
.SetContentText("Update location")
.SetOngoing(true)
.SetContentIntent(pendingIntent);
if (global::Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.O)
{
NotificationChannel notificationChannel = new NotificationChannel(foregroundChannelId, "Title", NotificationImportance.High);
notificationChannel.Importance = NotificationImportance.High;
notificationChannel.EnableLights(true);
notificationChannel.EnableVibration(true);
notificationChannel.SetShowBadge(true);
notificationChannel.SetVibrationPattern(new long[] { 100, 200, 300 });
var notifManager = context.GetSystemService(Context.NotificationService) as NotificationManager;
if (notifManager != null)
{
notifBuilder.SetChannelId(foregroundChannelId);
notifManager.CreateNotificationChannel(notificationChannel);
}
}
return notifBuilder.Build();
}
}
}

Loading…
Cancel
Save