i want know when gps on device tuned on, , location changed.
here i've done:
locationmanager mlocmanager = (locationmanager)getsystemservice(context.location_service); locationlistener mloclistener = new mylocationlistener(); mlocmanager.requestlocationupdates( locationmanager.gps_provider, 0, 0, mloclistener); public class mylocationlistener implements locationlistener { @override public void onlocationchanged(location loc) { toast.maketext( getapplicationcontext(),"onlocation changed",toast.length_short).show(); } @override public void onproviderdisabled(string provider) { toast.maketext( getapplicationcontext(),"providerdisabled",toast.length_short).show(); } @override public void onproviderenabled(string provider) { toast.maketext( getapplicationcontext(),"provideenabled",toast.length_short).show(); } @override public void onstatuschanged(string provider, int status, bundle extras) { } }
it working fine when app runs in foreground, when close it, won't more updates. i'd know how information continuosly until application uninstalled.
you need put in service , start service sticky.
also should think using fusedlocationmanager using googleplayservices.
for more info googleplayservices , locations read here
Comments
Post a Comment