Notification services Implemented
This commit is contained in:
parent
28e94c4a4c
commit
05778ee8ea
@ -0,0 +1,79 @@
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using GMCabsDriverAssistant.Services;
|
||||
using GMCabsDriverAssistantSolution.Platforms.Android;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
[assembly: Dependency(typeof(AndroidAlarmReceiver))]
|
||||
namespace GMCabsDriverAssistantSolution.Platforms.Android
|
||||
{
|
||||
[BroadcastReceiver(Name = "au.com.gmcabs.driverassistant.app.AndroidAlarmReceiver", Enabled = true, Exported = true, DirectBootAware = true)]
|
||||
public class AndroidAlarmReceiver : BroadcastReceiver, IAlarmService
|
||||
{
|
||||
[Obsolete]
|
||||
public override void OnReceive(Context context, Intent intent)
|
||||
{
|
||||
string foregroundChannelId = "GMCabsForeGroundServiceRunningChannel";
|
||||
var message = "Foreground Service Is On";
|
||||
var title = "Service Status";
|
||||
var resultIntent = new Intent(context, typeof(MainActivity));
|
||||
resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
|
||||
var pendingIntentFlags = (Build.VERSION.SdkInt >= BuildVersionCodes.S)
|
||||
? PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable
|
||||
: PendingIntentFlags.UpdateCurrent;
|
||||
|
||||
var pending = PendingIntent.GetActivity(context, 0,
|
||||
resultIntent,
|
||||
pendingIntentFlags);
|
||||
|
||||
var builder =
|
||||
new Notification.Builder(context)
|
||||
.SetSmallIcon(Resource.Drawable.ic_stat_ic_notification)
|
||||
//.SetColor(global::Android.App.Application.Context.GetColor(Resource.Color.color_notification_icon))
|
||||
.SetContentTitle(title)
|
||||
.SetContentText(message)
|
||||
.SetPriority((int)NotificationImportance.Max)
|
||||
.SetAutoCancel(true)
|
||||
.SetTimeoutAfter(60000);
|
||||
|
||||
builder.SetContentIntent(pending);
|
||||
var notification = builder.Build();
|
||||
var notifManager = global::Android.App.Application.Context.GetSystemService(global::Android.Content.Context.NotificationService) as NotificationManager;
|
||||
|
||||
if (global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.O)
|
||||
{
|
||||
var notificationChannel = new NotificationChannel(foregroundChannelId, "GMCabsAlarmManagerNotification", NotificationImportance.Low);
|
||||
notificationChannel.Importance = NotificationImportance.Low;
|
||||
notificationChannel.EnableLights(true);
|
||||
notificationChannel.EnableVibration(true);
|
||||
notificationChannel.SetShowBadge(true);
|
||||
notificationChannel.SetVibrationPattern(new long[] { 100, 200, 300 });
|
||||
if (builder != null)
|
||||
{
|
||||
builder.SetChannelId(foregroundChannelId);
|
||||
notifManager.CreateNotificationChannel(notificationChannel);
|
||||
}
|
||||
}
|
||||
notifManager.Notify(DateTime.Now.Millisecond, notification);
|
||||
}
|
||||
|
||||
public void StartMyAlarmService()
|
||||
{
|
||||
var alarmIntent = new Intent(global::Android.App.Application.Context, typeof(AndroidAlarmReceiver));
|
||||
var pendingIntentFlags = (Build.VERSION.SdkInt >= BuildVersionCodes.S)
|
||||
? PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable
|
||||
: PendingIntentFlags.UpdateCurrent;
|
||||
|
||||
var pending = PendingIntent.GetBroadcast(global::Android.App.Application.Context, 0, alarmIntent, pendingIntentFlags);
|
||||
var alarmManager = (AlarmManager)global::Android.App.Application.Context.GetSystemService(Context.AlarmService);
|
||||
alarmManager.Set(AlarmType.ElapsedRealtime, SystemClock.ElapsedRealtime() + 1 * 1000, pending);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true" package="au.com.gmcabs.driverassistant" android:usesCleartextTraffic="true"></application>
|
||||
<!--<application android:label="Driver App" android:icon="@mipmap/ic_launcher" android:theme="@style/MainTheme" android:supportsRtl="true" package="au.com.gmcabs.driverassistant" android:usesCleartextTraffic="true">
|
||||
<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity" android:theme="@style/Base.Theme.AppCompat" />
|
||||
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id" />
|
||||
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:value="@drawable/ic_stat_ic_notification" />
|
||||
<meta-data android:name="com.google.firebase.messaging.default_notification_color" android:value="@color/color_notification_icon" />
|
||||
</application>-->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
|
||||
<uses-permission android:name="com.google.android.things.permission.MANAGE_BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
</manifest>
|
@ -0,0 +1,70 @@
|
||||
using Android.App;
|
||||
using Android.OS;
|
||||
using GMCabsDriverAssistant.Services;
|
||||
using GMCabsDriverAssistantSolution.Platforms.Android.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Application = Android.App.Application;
|
||||
|
||||
[assembly: Dependency(typeof(NotificationChannelService))]
|
||||
namespace GMCabsDriverAssistantSolution.Platforms.Android.Services
|
||||
{
|
||||
public class NotificationChannelService : INotificationChannelService
|
||||
{
|
||||
#region Constants
|
||||
public const string TAG = nameof(GMCabsDriverAssistantApplication);
|
||||
public static string SILENT_NOTIFICATION_CHANNEL_ID = "GMCabsDriverAssistantSilentNotificationChannel";
|
||||
public static string SILENT_NOTIFICATION_CHANNEL_NAME = "GM Cabs Silent Notification Channel";
|
||||
public static string SOUND_NOTIFICATION_CHANNEL_ID = "GMCabsDriverAssistantChannel";
|
||||
public static string SOUND_NOTIFICATION_CHANNEL_NAME = "GM Cabs Notification Channel";
|
||||
public static string SYSTEM_SOUND_NOTIFICATION_CHANNEL_ID = "GMCabsDriverAssistantSystemChannel";
|
||||
public static string SYSTEM_SOUND_NOTIFICATION_CHANNEL_NAME = "GM Cabs System Notification Channel";
|
||||
#endregion
|
||||
|
||||
public void ManageNotificationChannelService()
|
||||
{
|
||||
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
|
||||
{
|
||||
var silentNotificationImportance = NotificationImportance.Low;
|
||||
var soundNotificationImportance = NotificationImportance.Max;
|
||||
var soundFileName = "newbooking";
|
||||
|
||||
|
||||
NotificationManager silentNotificationManager = Application.Context.GetSystemService(global::Android.Content.Context.NotificationService) as NotificationManager;
|
||||
NotificationManager customNotificationManager = Application.Context.GetSystemService(global::Android.Content.Context.NotificationService) as NotificationManager;
|
||||
NotificationManager systemNotificationManager = Application.Context.GetSystemService(global::Android.Content.Context.NotificationService) as NotificationManager;
|
||||
|
||||
/* Delete Notification Channel */
|
||||
silentNotificationManager.DeleteNotificationChannel(SILENT_NOTIFICATION_CHANNEL_ID);
|
||||
customNotificationManager.DeleteNotificationChannel(SOUND_NOTIFICATION_CHANNEL_ID);
|
||||
systemNotificationManager.DeleteNotificationChannel(SYSTEM_SOUND_NOTIFICATION_CHANNEL_ID);
|
||||
|
||||
/* Silent Notification Channel */
|
||||
|
||||
NotificationChannel silentNotificationchannel = new NotificationChannel(SILENT_NOTIFICATION_CHANNEL_ID, SILENT_NOTIFICATION_CHANNEL_NAME, silentNotificationImportance);
|
||||
silentNotificationchannel.EnableVibration(true);
|
||||
silentNotificationchannel.LockscreenVisibility = NotificationVisibility.Public;
|
||||
silentNotificationManager.CreateNotificationChannel(silentNotificationchannel);
|
||||
|
||||
/* Custom Sound Notification Channel */
|
||||
|
||||
NotificationChannel soundNotificationChannel = new NotificationChannel(SOUND_NOTIFICATION_CHANNEL_ID, SOUND_NOTIFICATION_CHANNEL_NAME, soundNotificationImportance);
|
||||
soundNotificationChannel.EnableVibration(true);
|
||||
soundNotificationChannel.LockscreenVisibility = NotificationVisibility.Public;
|
||||
soundNotificationChannel.SetSound(global::Android.Net.Uri.Parse("android.resource://au.com.gmcabs.driverassistant/raw/" + soundFileName), null);
|
||||
customNotificationManager.CreateNotificationChannel(soundNotificationChannel);
|
||||
|
||||
/* System Sound Notification Channel */
|
||||
|
||||
NotificationChannel systemSoundNotificationChannel = new NotificationChannel(SYSTEM_SOUND_NOTIFICATION_CHANNEL_ID, SYSTEM_SOUND_NOTIFICATION_CHANNEL_NAME, soundNotificationImportance);
|
||||
systemSoundNotificationChannel.EnableVibration(true);
|
||||
systemSoundNotificationChannel.LockscreenVisibility = NotificationVisibility.Public;
|
||||
systemNotificationManager.CreateNotificationChannel(systemSoundNotificationChannel);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -174,11 +174,11 @@ public partial class HomePage : ContentPage
|
||||
|
||||
private async void OnNotificationViewClicked(object sender, EventArgs e)
|
||||
{
|
||||
// await Navigation.PushAsync(new NotificationsPage());
|
||||
await Navigation.PushAsync(new NotificationsPage());
|
||||
}
|
||||
private async void OnBookingViewClicked(object sender, EventArgs e)
|
||||
{
|
||||
// await Navigation.PushAsync(new BookingsPage(_viewModel.CurrentLocation.Latitude, _viewModel.CurrentLocation.Longitude));
|
||||
await Navigation.PushAsync(new BookingsPage(_viewModel.CurrentLocation.Latitude, _viewModel.CurrentLocation.Longitude));
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
|
Loading…
x
Reference in New Issue
Block a user