I'm attempting to create a simple app to mock GPS coordinates. I have setup the correct permissions in manifest. The problem is actually mocking the address. I have tested the following code with no success:
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
ll = new MyLocationListener();
if (lm.getProvider("Test") == null) {
lm.addTestProvider("Test", false, false, false, false, false, false, false, 0, 1);
}
lm.setTestProviderEnabled("Test", true);
lm.requestLocationUpdates("Test", 0, 0, ll);
map.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng l) {
Location loc = new Location("Test");
loc.setLatitude(l.latitude);
loc.setLongitude(l.longitude);
loc.setAltitude(0);
loc.setAccuracy(10f);
loc.setElapsedRealtimeNanos(System.nanoTime());
loc.setTime(System.currentTimeMillis());
lm.setTestProviderLocation("Test", loc);
}
};
I have also attempted to use FusedLocationApi
which does work for any apps using the google framework. Google maps, for example, works perfectly fine.
Although the problem I have found with FusedLocationApi
is that it does not mock the location for any apps outside of the Google framework which is a problem. Apps outside the google framework generally report that "No GPS is being detected".
I really hope someone can guide me in the right direction!