开发者

Triggering LocationListener's event manually

Is there a way to manually trigger the code inside a LocationListener's onLoc开发者_StackOverflow中文版ationChanged method? It should receive a Location object with the last known location, I guess.


Sure thing, if it's your LocationListener - onLocationChanged() is a public method; just call it with whatever Location object you have on hand (maybe have your location listener cache it somewhere, or use LocationManager's getLastKnownLocation method to grab the last location seen from a specific provider and call onLocationChanged() with that).


You can use the setTestProviderLocation method of the LocationManager to mock new locations and have the onLocationChanged method of the registered listeners called when you want.

You should check the reference page. You also have an example here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜