I\'m trying to get this bit of code to work:
Testing GPS in Android
The problem is, when I run the test, onLocationChanged() is never called:
After adding and enabling your Provider just use this line to get the updates :
locationManager.requestLocationUpdates(MOCK_PROVIDER, 0, 0, this);
I recommend to use a method like this on activity start-up :
private void enableProvider() {
try {
locationManager.addTestProvider(
MOCK_PROVIDER,
false,
false,
false,
false,
true,
true,
true,
0,
5
);
} catch (IllegalArgumentException | SecurityException e) {
Log.w(TAG, "addTestProvider" + e.getMessage());
}
try {
locationManager.setTestProviderEnabled(MOCK_PROVIDER, true);
locationManager.requestLocationUpdates(MOCK_PROVIDER, 0, 0, this); <-- Update Request
} catch (IllegalArgumentException | SecurityException e) {
Log.w(TAG, "setTestProviderEnabled" + e.getMessage());
}
}
Handle the exceptions as well.