android - FragmentActivity and LocationListener -
i try current location of user using locationlistener in fragmentactivity (in order user supportmapfragment) implements locationlistener.
this code :
private void setlocationmanager() { if (lm == null) lm = (locationmanager) .getsystemservice(context.location_service); // exceptions thrown if provider not permitted. try { gps_enabled = lm.isproviderenabled(locationmanager.gps_provider); } catch (exception ex) { } try { network_enabled = lm .isproviderenabled(locationmanager.network_provider); } catch (exception ex) { } if (gps_enabled) { lm.requestlocationupdates(locationmanager.gps_provider, 0, 0, this); toast.maketext(homeactivity.this, "refresh gps", toast.length_short) .show(); } else { lm.requestlocationupdates(locationmanager.network_provider, 0, 0, this); toast.maketext(homeactivity.this, "refresh net", toast.length_short) .show(); } } @override public void onlocationchanged(location location) { mycurrentlocation = location; toast.maketext( homeactivity.this, "refresh == lat : " + mycurrentlocation.getlatitude() + " long : " + mycurrentlocation.getlongitude(), toast.length_short).show(); } @override public void onproviderdisabled(string provider) { toast.maketext(homeactivity.this, provider, toast.length_short).show(); } @override public void onproviderenabled(string provider) { toast.maketext(homeactivity.this, provider, toast.length_short).show(); } @override public void onstatuschanged(string provider, int status, bundle extras) { // todo auto-generated method stub }
the problem have are:
- the overriden method : onlocationchanged never called using network provider
- the overriden method : onproviderdisabled never called every time..
and never use : lm.removeupdate method
a reboot of samsung galaxy s3 did job..
hope helps.
Comments
Post a Comment