gps - Android LocationListener no hitting onLocationChanged -
i have class named gpstracker implements locationlistener interface.
public class gpstracker implements locationlistener { context context; locationmanager lm; in constructor set locationmanager , settings (i've omitted permissions part):
public gpstracker(context c) { context = c; ... (permission checking) lm = (locationmanager) context.getsystemservice(context.location_service); boolean isgpsenabled = lm.isproviderenabled(locationmanager.gps_provider); if(isgpsenabled){ lm.requestlocationupdates(locationmanager.gps_provider, 6000, 5, this); } else { toast.maketext(context, "please enable gps", toast.length_short).show(); } } in manifest file i've set these permissions gps:
<uses-permission android:name="android.permission.access_fine_location" /> <uses-permission android:name="android.permission.access_coarse_location" /> and i've overridden methods of 1 has functionality, onlocationchanged method:
@override public void onlocationchanged(location location) { inspectieoverzicht activity = (inspectieoverzicht) context; activity.getfirstfragment().updatedistance(location); } i create new gpstracker object in activity.
g = new gpstracker(this); i expect work. it'll ask permissions use gps , see in top gps icon it's working gps. onlocationchanged method never called.
i tried walking , down building i'm @ (maybe needs change) didn't work.
i've tried on virtual device change gps location , works charm. it's updating activity immediately.
i've tried on api 19, 23 , 26 (on emulated devices) worked. i've tried on api 23 on actual device doesn't seem work.
does knows i'm doing wrong here?
use both network provide coordinates if gps_provider not works
locationmanager.requestlocationupdates(locationmanager.network_provider, min_time_bw_updates, min_distance_change_for_updates, mylistener); locationmanager.requestlocationupdates(locationmanager.gps_provider, min_time_bw_updates, min_distance_change_for_updates, mylistener);
Comments
Post a Comment