GPS Locator not working in background

404 views
Skip to first unread message

Franz Mazenauer

unread,
Jan 24, 2025, 7:10:16 AM1/24/25
to DroidScript
Hi to all
I wrote an app which receives an SMS and then tries to get the current GPS location (latitude and longitude). My app is working fine as long as the app is in Foreground but when the app is in Background, the GPS locator change method is never called!
I know that using native Android programming GPS is working in Background.
Can this not be done using Droidscript?

Thanks to all appreciated replies.

Franz

Gurudas Gaonkar

unread,
Jan 27, 2025, 6:57:11 PM1/27/25
to DroidScript
Share SPK

Franz Mazenauer

unread,
Jan 28, 2025, 7:48:55 AM1/28/25
to DroidScript
Below is the piece of code without the SMS stuff which shows exactly, that the GPS locator change method is never called when running in background. When the code runs in foreground, the GPS locator method is called every second.

//Called when application is started.
function OnStart()
{
   i=0
   loc= app.CreateLocator("GPS")
   loc.SetOnChange(loc_OnChange)
   loc.SetRate(1)
   app.ShowPopup("before loc.Start")
   loc.Start()
}


function loc_OnChange(data)
{
   i++
   app.ShowPopup(i + " lat:" + data.latitude + " lng:" + data.longitude)
}

Dave

unread,
Feb 4, 2025, 6:17:21 PM2/4/25
to DroidScript
Recent versions of Android do not let you use the Locator in the background.  The latest beta (v2.75b3) coming later this week will allow you to create a foreground service to do it.

Dave

unread,
Feb 5, 2025, 4:45:10 AM2/5/25
to DroidScript
Note: You need to put _AddPermissions("Location") in your main file.

Gurudas Gaonkar

unread,
Feb 7, 2025, 2:49:16 PM2/7/25
to DroidScript

I have created a **GPS Location Tracking Project**. This project **displays real-time location updates** and **sends the location via SMS**.  
It includes **date & time, speed, and accuracy** along with GPS details.  

Check out my code and let me know your feedback! :)
GPS Tracker & Auto SMS Sender.spk

Gurudas Gaonkar

unread,
Feb 8, 2025, 6:14:38 AM2/8/25
to DroidScript
GPS Tracker & Auto SMS Sender2.spk

Franz Mazenauer

unread,
Feb 25, 2025, 6:38:30 AM2/25/25
to DroidScript
Hi Dave
you wrote "The latest beta (v2.75b3) coming later this week will allow you to create a foreground service to do it."
I installed now V2.76 but cannot find any hint about how to create a foreground service. Can you please comment on this.
Thanks a lot.
Cheers
Franz
Reply all
Reply to author
Forward
0 new messages