java - Android requestLocationUpdates doesn't call never to onLocationChanged in some terminals -
i'm working on app uses network location, i've recived users feedback says never pass block of code, i'm assuming problem location changed never called, happens in few diveces, , cant force failure in mine.
is there chance solve or control it? showing toast saying unable find location, work me...
i know if user reboot phone, location work, it's not solution users
i left code right here...
final locationmanager lm = (locationmanager) thisofactivity .getsystemservice(context.location_service); boolean network_enabled = lm .isproviderenabled(locationmanager.network_provider); // stuff location net_loc = lm.getlastknownlocation(locationmanager.network_provider); final locationlistener locationlistenernetwork = new locationlistener() { public void onlocationchanged(location location) { double lat = location.getlatitude(); double lon = location.getlongitude(); log.e("latlon", lat + "," + lon); lm.removeupdates(this); // stuff mytask task = new mytask(); if (progress.isshowing()) progress.dismiss(); task.execute(); thisofactivity.registerforcontextmenu(tweetlist); } public void onproviderdisabled(string provider) { thisofactivity .startactivityforresult( new intent( android.provider.settings.action_location_source_settings), 0); if (progress.isshowing()) progress.dismiss(); mainactivity.accionencuro = false; toast.maketext( thisofactivity.getapplicationcontext(), thisofactivity.getstring(r.string.location), toast.length_short).show(); } public void onproviderenabled(string provider) { } @override public void onstatuschanged(string provider, int status, bundle extras) { switch( status ) { case locationprovider.available: log.e("locprov", "available"); break; case locationprovider.out_of_service: log.e("locprov", "out_of_service"); break; case locationprovider.temporarily_unavailable: log.e("locprov", "temporarily_unavailable"); break; } } }; if (network_enabled) { lm.requestlocationupdates( locationmanager.network_provider, 0, 0, locationlistenernetwork); } else { thisofactivity .startactivityforresult( new intent( android.provider.settings.action_location_source_settings), 0); if (progress.isshowing()) progress.dismiss(); mainactivity.accionencuro = false; toast.maketext(thisofactivity.getapplicationcontext(), thisofactivity.getstring(r.string.location), toast.length_long).show(); }
i've tried next idea, think work, @ least location , not keep user waiting.
final locationmanager lm = (locationmanager) thisofactivity .getsystemservice(context.location_service); boolean network_enabled = lm .isproviderenabled(locationmanager.network_provider); // stuff locationlistener locationlistenernetwork = null; // constructor class mythread implements runnable { locationlistener locationlistenernetwork; public mythread(locationlistener lln) { locationlistenernetwork = lln; } public void run() { } } final handler myhandler = new handler(); //here's runnable/handler combo final runnable myrunnable = new mythread(locationlistenernetwork) { @override public void run() { if (locationlistenernetwork != null) lm.removeupdates(locationlistenernetwork); location location = lm.getlastknownlocation(locationmanager.network_provider); if(location != null) { double lat = location.getlatitude(); double lon = location.getlongitude(); log.e("latlon", lat + "," + lon); listview tweetlist = (listview) thisofactivity .findviewbyid(r.id.tweets); jsonupdateasynctask task = new jsonupdateasynctask( thisofactivity, double.tostring(lat), double.tostring(lon), tweetlist); if (progress.isshowing()) progress.dismiss(); task.execute(); thisofactivity.registerforcontextmenu(tweetlist); } else { if (progress.isshowing()) progress.dismiss(); mainactivity.accionencuro = false; toast.maketext(thisofactivity.getapplicationcontext(), thisofactivity.getstring(r.string.location), toast.length_long).show(); } } }; locationlistenernetwork = new locationlistener() { public void onlocationchanged(location location) { double lat = location.getlatitude(); double lon = location.getlongitude(); log.e("latlon", lat + "," + lon); lm.removeupdates(this); myhandler.removecallbacks(myrunnable); listview tweetlist = (listview) thisofactivity .findviewbyid(r.id.tweets); jsonupdateasynctask task = new jsonupdateasynctask( thisofactivity, double.tostring(lat), double.tostring(lon), tweetlist); if (progress.isshowing()) progress.dismiss(); task.execute(); thisofactivity.registerforcontextmenu(tweetlist); } public void onproviderdisabled(string provider) { thisofactivity .startactivityforresult( new intent( android.provider.settings.action_location_source_settings), 0); if (progress.isshowing()) progress.dismiss(); mainactivity.accionencuro = false; toast.maketext( thisofactivity.getapplicationcontext(), thisofactivity.getstring(r.string.location), toast.length_short).show(); } public void onproviderenabled(string provider) { } @override public void onstatuschanged(string provider, int status, bundle extras) { switch( status ) { case locationprovider.available: log.e("locprov", "available"); break; case locationprovider.out_of_service: log.e("locprov", "out_of_service"); break; case locationprovider.temporarily_unavailable: log.e("locprov", "temporarily_unavailable"); break; } } }; if (network_enabled) { myhandler.postdelayed(myrunnable, 10 * 1000); lm.requestlocationupdates(locationmanager.network_provider, 5000, 0,locationlistenernetwork); } else { // more stuff
opinions?
Comments
Post a Comment