Hello Basic4Android forum.
I am new with this and, as Visual Basic 6.0 programmer non professional, I am very glad and enthusiastic with B4A.
My question is: I need that the GPS is always ON for give me the speed value to a variable, but, when I recibe a call or the screen turn off, the GPS stops. How can I do that? It is possible?
Thanks Erel.
I tried with a background service, but it doesn't work, so I am trying with a foreground running service.
I can see the GPS active by the service, but I can't see the notification message or icon, to be secure that the foreground is there (and because I am learning...)
I am trying with this code.
In Main Activity
B4X:
'lots of lines
StartService(ActivoSiempre)
'more lines
In ActivoSiempre
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim vrNoti As Notification
Dim GPS1 As GPS
End Sub
Sub Service_Create
' ver si este código va aquí o si va en Service_Start
GPS1.Initialize("GPS")
If GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device.", True)
StartActivity(GPS1.LocationSettingsIntent)
Else
GPS1.start(0, 0)
End If
vrNoti.Initialize
vrNoti.Vibrate=True
vrNoti.Sound=False
vrNoti.Light=False
End Sub
Sub Service_Start (StartingIntent As Intent)
vrNoti.SetInfo("Kilometreador - Reinier", "Corriendo...", Main)
'vrNoti.Notify(1)
Service.StartForeground(1, vrNoti)
End Sub
I am making some wrong or there is a Trial Version limitation?
Sub GPS_LocationChanged (Location1 As Location)
vrLatitud= Location1.Latitude
vrLongitud= Location1.Longitude
vrVelocidad = Location1.Speed
vrVelocidadKM= vrVelocidad * 3.6
End Sub