- Home /
Can Unity do this? (Background GPS triggers)
Hello, Haven't tried Unity yet and the answers on the matter that I found on the forums are non-definitive in my opinion.
I just spent a month using another cross app development framework to discover it has no way to let an app in background keep monitoring gps positions and behave accordingly: the gps tracking and listening to events ends as soon as it is put in background. (yes, my fault, I should have checked it first). Basically, it is a simple touring app, I don't want the user to always keep the smartphone in their hand but rather enjoy the surroundings, then when they get to sensible hotspots, I make the device vibrate or play an audio file, or a notification ... the crux is, phone is in their pocket, possibly locked, and the listening for gps location or other triggers needs to be made in background.
So, now wiser and before I use up another month to see if it is possible or not by myself - is there a definitive answer on that? Some say that the app needs to be flagged as run in background BUT that that setting only works for web player and PC ... others say it is possible.
So, is it possible or not? the answer to this question would make me switch over to Unity over the previous framework, so it is vital for me to have a definitive answer, even better if there were a Proof of Concept app or code that I could try myself to see if it fits my bill ....
Many thanks!
Hi $$anonymous$$hariton! You were able to fix this? I have the same question, it is possible or not? Thanks in advance for any info.
No, you can't. Applications in the background are paused. This is a deliberate design decision at the OS level, since Android/iOS never really "close" apps - they are just suspended. If apps were allowed to continue in the background your phone would overheat very fast.
You can write a service that runs in the background (like the service that checks for emails, for example), but that service cannot have an interface.
Answer by splitpete · Jul 24, 2017 at 07:08 PM
This project was done in Unity and used background location and audio. That said, native code was needed for both iOS and Android in order to make it work.
Answer by olegekbondar · Apr 30, 2017 at 05:23 PM
I don't seem to be able to make it work. I am only interested in the Android part. How do I remove any iOS dependencies as I don't have XCode, and am running all on windows?
Answer by Khariton · Jul 25, 2017 at 05:20 PM
Thanks @splitpete , that's a very interesting use case. what was the part that needed native code ?
The background location/audio part. I suppose it doesn't answer the original question but it is an example of a Unity app which calls native code to enable that functionality.
Well, it kind of does ... I read it as "it's not possible to do background geofencing without native code". Thanks
Your answer
Follow this Question
Related Questions
iOS game - Run GPS in background? 2 Answers
How can I have GPS enabled iOS app stay in the background? 0 Answers
Speech Recognition in background doesn't work correctly! 2 Answers
Keep unity running when minimized on iOS and Android 2 Answers
Keep app running in background for GPS tracking on iOS and Android? 2 Answers