【发布时间】:2011-05-16 09:07:33
【问题描述】:
我正在尝试让这段代码工作:
问题是,当我运行测试时,永远不会调用 onLocationChanged():
public class LocationTest0 extends AndroidTestCase implements LocationListener {
private Location received = null;
public void testExample() {
LocationManager lm = (LocationManager)this.getContext().getSystemService(Context.LOCATION_SERVICE);
String testProvider = "Test";
if (null == lm.getProvider(testProvider)){
lm.addTestProvider(testProvider, false, false, false, false, false, false, false, Criteria.POWER_LOW, Criteria.ACCURACY_FINE);
}
lm.setTestProviderEnabled(testProvider, true);
lm.requestLocationUpdates(testProvider, 0, 0, this);
lm.setTestProviderStatus(testProvider, LocationProvider.AVAILABLE, null, System.currentTimeMillis());
Location location = new Location(testProvider);
location.setLatitude(1.0);
location.setLongitude(2.0);
location.setTime(System.currentTimeMillis());
lm.setTestProviderLocation(testProvider, location);
Assert.assertFalse("Received Location is null", received == null );
lm.removeTestProvider(testProvider);
}
@Override
public void onLocationChanged(Location location) {
received = location;
Log.d("LocationTest0", "onLocationChanged CALLED");
// Never gets called
}
【问题讨论】:
-
你把所有的权限都放到manifest里面了吗?
-
是的,George,它就在那里 - 我知道没关系,因为它引发了我之前更正的权限错误。
标签: android junit locationmanager