From 28e94c4a4cf277b1878e6f8f26e79c227b4c977b Mon Sep 17 00:00:00 2001 From: Kaustav Chaudhuri Date: Mon, 15 May 2023 17:21:20 +0530 Subject: [PATCH] BootBroadcastReceiver class implemented --- .../Android/BootBroadcastReceiver.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 GMCabsDriverAssistantSolution/Platforms/Android/BootBroadcastReceiver.cs diff --git a/GMCabsDriverAssistantSolution/Platforms/Android/BootBroadcastReceiver.cs b/GMCabsDriverAssistantSolution/Platforms/Android/BootBroadcastReceiver.cs new file mode 100644 index 0000000..52ee14d --- /dev/null +++ b/GMCabsDriverAssistantSolution/Platforms/Android/BootBroadcastReceiver.cs @@ -0,0 +1,39 @@ +using Android.App; +using Android.Content; +using GMCabsDriverAssistantSolution.Platforms.Android.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static Java.Util.Jar.Attributes; + +namespace GMCabsDriverAssistantSolution.Platforms.Android +{ + [BroadcastReceiver(Name = "au.com.gmcabs.driverassistant.app.BootBroadcastReceiver", Enabled = true, Exported = true, DirectBootAware = true)] + [IntentFilter(new[] { Intent.ActionBootCompleted })] + public class BootBroadcastReceiver : BroadcastReceiver + { + public override void OnReceive(Context context, Intent intent) + { + string isForeground = Preferences.Get("isForeground", null); + if (intent.Action.Equals(Intent.ActionBootCompleted)) + { + if (isForeground == "YES") + { + var foreGroundServiceIntent = new Intent(global::Android.App.Application.Context, typeof(AndroidLocationService)); + if (global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.O) + { + global::Android.App.Application.Context.StartForegroundService(intent); + context.StartForegroundService(foreGroundServiceIntent); + } + else + { + global::Android.App.Application.Context.StartService(intent); + context.StartService(foreGroundServiceIntent); + } + } + } + } + } +}