*** It seems to be working again after I restarted my phone.
I have created a service that uses fusedlocationprovider to send location updates back to a central server. It was working fine a couple of days ago, but it now seems to have stopped working. I have the service set to run in the foreground. When the app is launched, and the service first runs, all of the initialization occurs and I get a FusedLocation_ConnectionSuccess event fired and a single FusedLocation_LocationChanged event. But then i do not get any more LocationChanged events firing. I added a Toast Message to the event so I could move around and see if it was being called and it is not. And I can see the service is still loaded as it is showing up in the notifications area.
The only change is that I am around 900km away from where I was when this was last working, but I don't see why that would make any difference.
Any ideas of why I would not be getting any locationchange events?
Below is the service code related to the creation and events
I have created a service that uses fusedlocationprovider to send location updates back to a central server. It was working fine a couple of days ago, but it now seems to have stopped working. I have the service set to run in the foreground. When the app is launched, and the service first runs, all of the initialization occurs and I get a FusedLocation_ConnectionSuccess event fired and a single FusedLocation_LocationChanged event. But then i do not get any more LocationChanged events firing. I added a Toast Message to the event so I could move around and see if it was being called and it is not. And I can see the service is still loaded as it is showing up in the notifications area.
The only change is that I am around 900km away from where I was when this was last working, but I don't see why that would make any difference.
Any ideas of why I would not be getting any locationchange events?
Below is the service code related to the creation and events
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Fuse As FusedLocationProvider
Dim count As Int
Dim time As Long
Dim sNotif As Notification
Dim LastSentLoc As Location
Dim LastSentTics As Long
Dim CurrentLoc As Location
Dim DbFileName2 As String : DbFileName2 = "workorderpref.db"
Dim Terminate As Boolean
Dim FirstTime As Boolean
Dim sTim As Int
Dim eTim As Int
Dim dDay As String
End Sub
Sub Service_Create
sNotif.Initialize
sNotif.Icon = "icon"
sNotif.SetInfo("Work Orders","Time Clock...",Main)
sNotif.Sound = False
sNotif.Notify(1)
CurrentLoc.Initialize
LastSentLoc.Initialize
Service.StartForeground(1,sNotif)
Fuse.Initialize("FusedLocation")
ToastMessageShow("Fuse Initialized from Service Create "&DateTime.Date(DateTime.Now)& " " & DateTime.Time(DateTime.Now),False)
Log ("Fuse Initialized from Service Create "&DateTime.Date(DateTime.Now)& " " & DateTime.Time(DateTime.Now))
FirstTime=True
End Sub
Sub Service_Start (StartingIntent As Intent)
Fuse.Connect
Log ("Fuse Started "&DateTime.Date(DateTime.Now)& " " & DateTime.Time(DateTime.Now))
ToastMessageShow("Fuse Started "&DateTime.Date(DateTime.Now)& " " & DateTime.Time(DateTime.Now),False)
End Sub
Sub Service_Destroy
Fuse.Disconnect
End Sub
Sub FusedLocation_ConnectionFailed(ConnectionResult1 As Int)
ToastMessageShow("FusedLocationProvider1_ConnectionFailed",False)
Log("FusedLocationProvider1_ConnectionFailed")
Select ConnectionResult1
Case Fuse.ConnectionResult.NETWORK_ERROR
' a network error has occurred, this is likely to be a recoverable error
' so try to connect again
Fuse.Connect
Case Else
' TODO handle other errors
End Select
End Sub
Sub FusedLocation_ConnectionSuccess
Log("fuse_ConnectionSuccess")
ToastMessageShow("fuse_ConnectionSuccess",False)
If CurrentLoc.IsInitialized = False Then
CurrentLoc.Initialize
End If
If LastSentLoc.IsInitialized = False Then
LastSentLoc.Initialize
End If
CurrentLoc = Fuse.GetLastKnownLocation
SendLocation(False)
Log("long,lat"&CurrentLoc.Longitude&","&CurrentLoc.Latitude)
Dim LocationRequest1 As LocationRequest
LocationRequest1.Initialize
LocationRequest1.SetInterval(1000) ' 30000 milliseconds (30 seconds)
LocationRequest1.SetPriority(LocationRequest1.Priority.PRIORITY_HIGH_ACCURACY)
LocationRequest1.SetSmallestDisplacement(1) ' 1 meter
Fuse.RequestLocationUpdates(LocationRequest1)
End Sub
Sub FusedLocation_LocationChanged(Location1 As Location)
Log("Location Changed "&DateTime.Date(DateTime.Now)& " " & DateTime.Time(DateTime.Now))
ToastMessageShow("Location Changed "&Location1.Accuracy& " "&Location1.DistanceTo(LastSentLoc),False)
If Location1.Accuracy <=100 Then
CurrentLoc=Location1
Log("Location saved" )
If LastSentLoc.Longitude = 0 Or Location1.DistanceTo(LastSentLoc)>100 Or Terminate Or DateTime.Now-LastSentTics>10000 Then ' Moved over 100 meters, or every 10000 ms (10 seconds) send an update
SendLocation(False)
LastSentTics=DateTime.Now
End If
End If
End Sub
Last edited: