Currently, I’m developing an application that injects locations into Android. This application should inject locations at specific moments. Before and after, normal GPS should be used.
My software is able to switch to mock locations and inject locations succesfully. But I am not able to make Android listen to normal GPS again.
My code to set-up:
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mLocationManager.addTestProvider(LocationManager.GPS_PROVIDER, false, false, false, false, true, true, true, 0, /*magic*/5);
mLocationManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true);
My failing attempt to stop:
mLocationManager.setTestProviderEnabled(PROVIDER_NAME, false);
mLocationManager.removeTestProvider(PROVIDER_NAME);
My question: how to stop provide mock locations and resume default Android GPS?
I found out it was due to two reasons.
First, the
setTestProviderEnabled(PROVIDER_NAME, false)call was not needed. Second, when looking into the Android source code, it showed that the normal GPS will not be activated automatically. By requesting location updates after theremoveTestProvider()call, the normal GPS signal will be activated and everything works fine.