android - Is it better to requestLocationUpdates in bursts with short intervals, or over a long period of time with long intervals? -


i have android app wants track user's movements throughout day , report them each week trends. thought long user had location services and/or gps enabled, system trying keep user's location date. however, after reading article on location strategies, realized not case.

it appears that, though user has checked boxes location services or gps, receivers attempt determine location of device after application calls requestlocationupdates , continue until call removeupdates. (if not correct, please let me know).

since app needs "rough" idea of device's movements, thinking recording location of device once every 5 minutes or so. however, neither of examples in article described kind of application. both examples more determining location of device @ specific point in time rather trying "follow" device around: tagging user-created content location @ created , locating nearby points of interest.

my question is, more efficient have app "wake up" every 5 minutes , use 1 of techniques in article determine device's current location (by beginning listen, taking several samples, determining best sample, stop listening, , go sleep), or better start listening updates , give minimum time between updates of 5 minutes , never stop listening?

use broastcastreceiver new locations @ regular intervals, if app isn't visible. don't use service, might killed.

pendingintent pendingintent = pendingintent.getbroadcast(this, 0, new intent(mylocationbroadcastreceiver.action), 0); locationmanager locationmanager = (locationmanager) getsystemservice(context.location_service); locationmanager.requestlocationupdates(locationmanager.network_provider, 5 * 60 * 1000, 100, pendingintent); locationmanager.requestlocationupdates(locationmanager.gps_provider, 5 * 60 * 1000, 100, pendingintent); locationmanager.requestlocationupdates(locationmanager.passive_provider, 0, 0, pendingintent); 

don't forget add action string manifest.xml, , add access_fine_location permission there (for gps). if don't want gps, use access_coarse_location.

<receiver android:name="mylocationbroadcastreceiver" android:process=":mylocationbroadcastreceiver" >     <intent-filter>         <action android:name="hello.world.broadcastreceiver.location_changed" />     </intent-filter> </receiver> <uses-permission android:name="android.permission.get_accounts" /> 

in broastcastreceiver.onreceive(), you'll have sort out get. throw away new locations have less distance previous location new accuracy. throw away "recent" locations if have significant worse accuracy previous one. , gps fixes accuracy higher 100m worthless. you'll have store locations in file or in preferences, because broastcastreceiver object won't exist between onreceive() calls.

public class mylocationbroadcastreceiver extends broadcastreceiver {     static public final string action = "hello.world.broadcastreceiver.location_changed";      public void onreceive(context context, intent intent)     {         location location = (location) intent.getextras().get(locationmanager.key_location_changed);         if (location == null)         {             return;         }          // strategies here     } } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -