-1

I am developing an app which tracks the user location for every 10-20 secs. In order to make it work in the background and mobile locked stage, I had to make the following code edits:

In Android:

I added permission of "Wake_Lock" and added a line of code in MainActivity.cs like

this.Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);

In iOS (AppDelegate.cs):

UIApplication.SharedApplication.IdleTimerDisabled = true;

This makes the functionality good and it is tracking the location for every 10 secs even in background and mobile is locked which is good. But by adding this code the battery usage by the app is increased drastically.

Can anyone please help me if I am doing anything wrong and suggest me any idea to get the battery usage problem solved.

Stedy
  • 7,359
  • 14
  • 57
  • 77
Praveen Baruri
  • 330
  • 3
  • 19

1 Answers1

0

Instead of using "UIApplication.SharedApplication.IdleTimerDisabled = true;" to prevent the phone goes into sleep mode, could you try to use the "Background Location"?

You can take a look in this Demo app.

Json
  • 1,655
  • 1
  • 13
  • 21
  • Thanks Janson.It works for iOS but what can i do for Android? – Praveen Baruri Oct 05 '17 at 05:23
  • Please note that it is a "Xamarin" solution not "Xamarin.Forms". It included the demo code for both iOS and Android platform. – Json Oct 05 '17 at 05:35
  • Thanks for your replies Janson I am doing a cross platform xamarin.forms app – Praveen Baruri Oct 05 '17 at 05:44
  • Unfortunately, not everything can be abstracted,so Xamarin.Forms has it limitation.Below URL is a reference for Xamarin.Forms backgrounding (http://arteksoftware.com/backgrounding-with-xamarin-forms/), you can have a look and try to implement the location service with it.Hope it could help – Json Oct 05 '17 at 06:14