Removing Mock GPS Provider Does Not Repair Real GPS

I am writing a program that, among many things, uses GPS data from a secondary source. I implement this using the Mock Location API:

LocationManager locationManager = ...

locationManager.addTestProvider(LocationManager.GPS_PROVIDER, false, false, false, false, false, true, true, Criteria.POWER_LOW, Criteria.ACCURACY_FINE);

locationManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true);
locationManager.setTestProviderStatus(LocationManager.GPS_PROVIDER, LocationProvider.AVAILABLE, null, System.currentTimeMillis());

Location location = ...
location.setLatitude(...);
location.setLongitude(...);
... // etc.
locationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER, location);

The good news: it works great! There were parties, confetti and a marching band. The bad news: if I decide that I want to use the main GPS source again, deleting this layout doesn't seem to work; instead, I am not getting new GPS updates. As if the main GPS source was turned off by adding the layout and deleting the layout, it never brought it back.

locationManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, false);
locationManager.clearTestProviderEnabled(LocationManager.GPS_PROVIDER);
locationManager.clearTestProviderLocation(LocationManager.GPS_PROVIDER);
locationManager.removeTestProvider(LocationManager.GPS_PROVIDER);

Is there another step that needs to be done to restore the primary GPS source?

+3
source share
1 answer

. , , , , Android API.

0

All Articles