Android Question GPS Background Tracking..

nicieri

Active Member
Licensed User
Longtime User
In order to track in the background, I see according to the tutorial that the notification is necessary, and if I remove that part of the code, then the tracking no longer works.

My question is, is there any other way I can do this? How does Waze do it in the background for example? without showing that notification?

I don't want the user to see that notification.


B4X:
Sub Service_Start (StartingIntent As Intent)
    'Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
    Service.StartForeground(nid, CreateNotification("..."))
    StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, True)
    Track
End Sub


Sub CreateNotification (Body As String) As Notification
    Dim notification As Notification
    notification.Initialize2(notification.IMPORTANCE_LOW)
    notification.Icon = "icon"
    notification.Number=0
    'notification.AutoCancel=True
    notification.SetInfo("Tracking", Body, Main)
    Return notification
End Sub
 

josejad

Expert
Licensed User
Longtime User
So... you don't see waze notification?

 
Upvote 1

Sandman

Expert
Licensed User
Longtime User
I see a Waze notification.

Just buy into how it works nowadays, it's a waste of time and energy to try to work around and outsmart the system.
 
Upvote 0

nicieri

Active Member
Licensed User
Longtime User
Ok, Thanks...


The problem is that when the user closes the app, the service is still active, and since it is tracking, when the user reopens the app, the GPS service no longer works.

1.- Can the service be completely eliminated when closing the app?

2.- If I try to use the notification with NB6, it is no longer seen in this case.


B4X:
Sub CreateNotification (Body As String) As Notification
'    Dim notification As Notification
'    notification.Initialize2(notification.IMPORTANCE_LOW)
'    notification.Icon = "icon"
'    notification.Number=0
'    'notification.AutoCancel=True
'    notification.SetInfo("Tracking", Body, Main)
'    Return notification


'    Dim n As NB6
'    n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(bm)
'    n.Build("Title", "Content", "tag1", Me).Notify(4) 'It will be Main (or any other activity) instead of Me if called from a service.

    Dim n As NB6
    n.Initialize("default", Application.LabelName, "LOW").SmallIcon(bm)
    n.SetDefaults(False, False, False)
    Log(Body)
    Return n.Build("MyApp", "Tracking...", "tag", Main)

End Sub

What is the correct way to do it? So that when the app ends, everything ends?

B4X:
Sub Service_Start (StartingIntent As Intent)
    'Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
    Service.StartForeground(nid, CreateNotification("..."))
    StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, True)
    Track
End Sub

Public Sub StartLocationUpdates
    flp.RequestLocationUpdates(CreateLocationRequest)
End Sub

Private Sub CreateLocationRequest As LocationRequest
    Dim lr As LocationRequest
    lr.Initialize
    lr.SetInterval(5000)    '    1000 milliseconds
    lr.SetPriority(lr.Priority.PRIORITY_HIGH_ACCURACY)
    lr.SetSmallestDisplacement(3)    '    1 meter
    Return lr
End Sub
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
see
see:
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…