1

I am interested in creating an android app that:

  • Does not have a UI (no visible activity).
  • I suppose this would be an Android service unless there is a better alternative.
  • Service should run indefinitely to run a GPS location listener for location updates.
  • App should not appear when the user brings up all apps on the device.
  • App/service should be able to run while the phone is on but the display is off.

Is this possible? What is the recommended way to achieve this? If not, would an alternative solution be to use an alarm manager that launches the invisible service at timed intervals?

code
  • 5,294
  • 16
  • 62
  • 113
  • Are you doing this as an app for a Custom ROM or retail Android device. Also how frequently do you need to get location data. Be aware of background restrictions in the more recent releases of Android: https://developer.android.com/about/versions/oreo/background-location-limits – Morrison Chang Feb 17 '19 at 01:33
  • Hi codeshark, I am working on an app, with almost similar requirements as above. But I was not able to come up with a solution because of limitations in newer versions. If you can share your findings, that would be helpful. Thanks – DS009 May 05 '20 at 00:23

1 Answers1

0

One of the thing that should be considered is how to do something indefinitely. Android guarantees that any foreground related thing like activity or foreground service wont be killed. So having a foreground service which wraps GPS stuff could be good solution.

Or a foreground service(same above) could be triggered by alarm manager, then does the required GPS stuff, finally sleeps again until next tick.

The key thing for you is being on foreground. So it will be cure for location background limitations and to not be candidate to be killed.


I just gave foreground service and activity samples for being alive. So the minimum invisibility for you is having a foreground service has notification.

Yes that's possible, setting up an alarm to work periodically. But one thing again, when device wakes up due to your alarm, android will give you short time to do something, because it'll continue sleeping.

But this short time maybe be won't enough to make request and receive for locations. App has to hinder the device from sleeping

https://developer.android.com/training/scheduling/wakelock#cpu

Android - periodically wake up from standby mode?

https://developer.android.com/training/scheduling/alarms

And finally, alarm manager, foreground service are able to do things(from your perspective) when display is off, if the app fulfill the requirements above

blackkara
  • 4,900
  • 4
  • 28
  • 58
  • Thanks blackkara . By foreground service, would that mean this contains an activity that has a UI? I am interested in having it invisible – code Feb 17 '19 at 04:02
  • Is it possible to create an alarm manager that launches the service to briefly get the GPS coordinates (with no user interface) every 10 minutes ? – code Feb 17 '19 at 04:03
  • Also, would this be able to run while the phone is on but the phone display is off? – code Feb 17 '19 at 04:03