From 1b9023d7107c770554caec5d2ee26a5a3004e5fe Mon Sep 17 00:00:00 2001 From: Kaustav Chaudhuri Date: Thu, 25 May 2023 13:34:30 +0530 Subject: [PATCH] Battery implementation Service class added. --- .../Services/BatteryImplementationService.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 GMCabsDriverAssistantSolution/Platforms/Android/Services/BatteryImplementationService.cs diff --git a/GMCabsDriverAssistantSolution/Platforms/Android/Services/BatteryImplementationService.cs b/GMCabsDriverAssistantSolution/Platforms/Android/Services/BatteryImplementationService.cs new file mode 100644 index 0000000..ad83007 --- /dev/null +++ b/GMCabsDriverAssistantSolution/Platforms/Android/Services/BatteryImplementationService.cs @@ -0,0 +1,37 @@ +using Android.Content; +using Android.OS; +using GMCabsDriverAssistant.Services; +using GMCabsDriverAssistantSolution.Platforms.Android.Services; +using Microsoft.Maui.Controls.Compatibility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +[assembly: Dependency(typeof(BatteryImplementationService))] +namespace GMCabsDriverAssistantSolution.Platforms.Android.Services +{ + public class BatteryImplementationService : IBatteryInfo + { + public bool CheckIsIgnoringBatteryOptimizations() + { + + PowerManager pm = (PowerManager)global::Android.App.Application.Context.GetSystemService(Context.PowerService); + //enter you package name of your application + bool result = pm.IsIgnoringBatteryOptimizations("au.com.gmcabs.driverassistant"); + return result; + } + + [System.Obsolete] + public void StartSetting() + { + Intent intent = new Intent(); + + intent.SetAction(global::Android.Provider.Settings.ActionIgnoreBatteryOptimizationSettings); + global::Android.App.Application.Context.StartActivity(intent); + Launcher.OpenAsync(intent.ToString()); + // StartActivity(intent); + } + } +}