I would like to know how to receive GPS when the Android app is in the background. Is there a complete tutorial to explain it?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
You need to use Service concept instead of activity. http://developer.android.com/guide/components/services.html
Here is a good sample: Background service needs to send GPS location on server
You need to use a AlarmManager to activate a pending intent (via a broadcast receiver) to launch a background service.
Some sample code for you
In your MainActivity
AlarmReceiver class
The BroadcastReceiver
The background Service. Here you will notice 2 important points
All this works in a production app on the play store.
Lastly, don't forget your manifest thing.
You can use a Service which always runs in the background..and in the background service you can get the current latitude and longitude and you can further convert these lats and longs into proper location using the Android geocoder class... check the follwing link:
http://www.codeproject.com/KB/android/GPSLocator.aspx
The thing which you will do in Activity can be done in service also..in the onStart() of Service....