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.

39 lines
1.6 KiB

  1. using Android.App;
  2. using Android.Content;
  3. using GMCabsDriverAssistantSolution.Platforms.Android.Services;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using static Java.Util.Jar.Attributes;
  10. namespace GMCabsDriverAssistantSolution.Platforms.Android
  11. {
  12. [BroadcastReceiver(Name = "au.com.gmcabs.driverassistant.app.BootBroadcastReceiver", Enabled = true, Exported = true, DirectBootAware = true)]
  13. [IntentFilter(new[] { Intent.ActionBootCompleted })]
  14. public class BootBroadcastReceiver : BroadcastReceiver
  15. {
  16. public override void OnReceive(Context context, Intent intent)
  17. {
  18. string isForeground = Preferences.Get("isForeground", null);
  19. if (intent.Action.Equals(Intent.ActionBootCompleted))
  20. {
  21. if (isForeground == "YES")
  22. {
  23. var foreGroundServiceIntent = new Intent(global::Android.App.Application.Context, typeof(AndroidLocationService));
  24. if (global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.O)
  25. {
  26. global::Android.App.Application.Context.StartForegroundService(intent);
  27. context.StartForegroundService(foreGroundServiceIntent);
  28. }
  29. else
  30. {
  31. global::Android.App.Application.Context.StartService(intent);
  32. context.StartService(foreGroundServiceIntent);
  33. }
  34. }
  35. }
  36. }
  37. }
  38. }