Android - onLocationChanged is not called

摘要:Android - onLocationChanged is not called

遇到一個問題,就是使用傳統取得坐標的方式不管用的問題,不管你使用什麼Provider,或是否全都啟用了requestLocationUpdates

總之你取得的 getLastKnownLocation 都是 null

 

這部份跟機器有關,而我遇到的機器剛好就是Sony,當然也有可能是其它的

而以下這篇的討論,告訴了問題原因,只要將機器重新開機就可以了。

 

https://code.google.com/p/android/issues/detail?id=57707

 

This apparently is a bug which could be reproduced on different devices, not only Samsung but also HTC, even a Google Nexus (see SO links down this posting).

After some time (hours to days), Android (starting 4.1? 4.2?) just does not call the listener anymore.
Most apps I have running using the NETWORK provider don't get updates after that.
Reboot fixes the issue and all apps seem to find the proper location again.

Checking the providers' getLastKnownLocation().getTime() shows it's very old data.
What's really interesting, that Google Maps actually seems to work. Some would assume that it would not, too; and some would assume the getTime() for the providers lastknown location would get updated, but they still show with old locations and old timestamp.


http://stackoverflow.com/questions/12630413/has-network-provider-behavior-changed-in-android-4-1-1?lq=1
http://stackoverflow.com/questions/13594932/network-provider-not-providing-updated-locations
http://stackoverflow.com/questions/15747543/locationlistener-of-network-provider-is-enabled-but-onlocationchanged-is-never?lq=1

I actually do experience this problem, too, and it's not a real solution to tell my customers "you have to reboot your device".

 

而且說明了 在4.1、4.2以前,似乎這樣的做法,而4.2之後,可能已經不再使用這種方法去處理取得gps坐標了。

 

該怎麼做,就等我真正研究出來,再寫一篇文章,

目前,就只能Reboot解決問題。