Hello,
I am trying to develop GPS Tracker Service, and my app is running fine when the App is Alive.
But when the App is in Sleep mode or in background the GPS tracker is not working and not providing any lat/long after some time.
The below link I am following but it is not working. After 1 minute of sleep the GPS tracking stop sending lat/long.
https://www.b4x.com/android/forum/threads/continous-background-gps-tracking.110628/#content
https://www.b4x.com/android/forum/threads/background-location-tracking.99873/
The below is the code block:
Please advice on this.....
Thanks
I am trying to develop GPS Tracker Service, and my app is running fine when the App is Alive.
But when the App is in Sleep mode or in background the GPS tracker is not working and not providing any lat/long after some time.
The below link I am following but it is not working. After 1 minute of sleep the GPS tracking stop sending lat/long.
https://www.b4x.com/android/forum/threads/continous-background-gps-tracking.110628/#content
https://www.b4x.com/android/forum/threads/background-location-tracking.99873/
The below is the code block:
B4X:
Sub Service_Create
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER 'we are handling it ourselves
GPS.Initialize("gps")
lock.PartialLock
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StartForeground(nid, CreateNotification("..."))
StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, True)
Track
End Sub
B4X:
Public Sub Track
If Tracking Then Return
If Main.rp.Check(Main.rp.PERMISSION_ACCESS_FINE_LOCATION) = False Then
Log("No permission")
Return
End If
GPS.Start(0, 0)
Tracking = True
End Sub
Sub GPS_LocationChanged (Location1 As Location)
Dim strLoc As String
If DateTime.Now > LastUpdateTime + 10 * DateTime.TicksPerSecond Then
Dim n As Notification = CreateNotification($"$2.5{Location1.Latitude} / $2.5{Location1.Longitude}"$)
n.Notify(nid)
LastUpdateTime = DateTime.Now
gpslat = Location1.Latitude
gpslong = Location1.Longitude
If gpslat>0 And gpslong>0 Then
'CallSubDelayed2(Main,"Update_Location",Location1)
Dim bc As ByteConverter
strLoc=gpslat & "/" &gpslong '& qrActivity.sessionId ''''"newloc_" &
If Starter.mqtt.Connected Then
Starter.mqtt.Publish("driver_" & qrActivity.sessionId,bc.StringToBytes(strLoc ,"UTF8"))
Else
Log("MQTT not connected")
End If
ToastMessageShow(gpslat & "/" &gpslong,True)
End If
End If
End Sub
Please advice on this.....
Thanks