android - could not get updated location in -
in application setting timer of 10 sec current location calling locationmanager.requestlocationupdates(); problem couldnt updated location instead gives same latitude , longitude application has started..
below code written in service.. , suggestions appreciated
public class demoservice extends service{ locationmanager locationmanager; public timer timer; public static int i; private string file_name = "location.txt"; @override public ibinder onbind(intent intent) { // todo auto-generated method stub return null; } @override public void onstart(intent intent, int startid) { // todo auto-generated method stub super.onstart(intent, startid); locationmanager = (locationmanager) this.getsystemservice(context.location_service); toast.maketext(getapplicationcontext(), "onstart()....", toast.length_short).show(); timer = new timer(); timer.schedule(new maintask(), 0, 10*1000); } @override public void oncreate() { // todo auto-generated method stub super.oncreate(); toast.maketext(getapplicationcontext(), "oncreate()....", toast.length_short).show(); } @override public void ondestroy() { // todo auto-generated method stub super.ondestroy(); toast.maketext(getapplicationcontext(), "ondestroy()....", toast.length_short).show(); timer.cancel(); } private class maintask extends timertask { public void run() { toasthandler.sendemptymessage(0); } } private final handler toasthandler = new handler() { @override public void handlemessage(message msg) { toast.maketext(getapplicationcontext(), "test "+(i), toast.length_short).show(); locationmanager.requestlocationupdates(locationmanager.network_provider, 0, 0, new mylocationlisterner()); } }; public class mylocationlisterner implements locationlistener{ @override public void onlocationchanged(location location) { // todo auto-generated method stub i++; toast.maketext(demoservice.this, "\nlat : "+location.getlatitude()+"\nlog : "+location.getlongitude(), toast.length_short).show(); savetofile(location); locationmanager.removeupdates(this); } @override public void onstatuschanged(string provider, int status, bundle extras) { // todo auto-generated method stub toast.maketext(demoservice.this,"got onlocationchanged..",toast.length_short).show(); system.out.println("got onstatuschanged"); } @override public void onproviderenabled(string provider) { // todo auto-generated method stub toast.maketext(demoservice.this,"got onlocationchanged..",toast.length_short).show(); system.out.println("got onproviderenabled"); } @override public void onproviderdisabled(string provider) { // todo auto-generated method stub toast.maketext(demoservice.this,"got onlocationchanged..",toast.length_short).show(); system.out.println("got onproviderdisabled"); }
i achieved resultant effect cwac location poller efficiently got current location of alarm manager less consumption of battery
Comments
Post a Comment