开发者

Triggering LocationListener's event manually

开发者 https://www.devze.com 2023-01-23 22:50 出处:网络
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.S

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

精彩评论

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