Description
I had a problem while trying to use local locks for Android. My main goal is to install the Android Android navigator to think that we are in a different place, a fake AKA GPS receiver.
Current attempts
Currently, I have tried two different similar solutions available on both of these sites:
Both textbooks since 2012, I do not know if they are outdated or it is difficult for me to do their job.
Coding development
First, I will make sure that I have permissions:
- ACCESS_COARSE_LOCATION
- ACCESS_FINE_LOCATION
- ACCESS_MOCK_LOCATION *
: 1 2 , . , requestPermissions. , AndroidManifest.xml .
, APP > a > MOCK.
, , , OnCreate OnClick :
public void mockLocation(){
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy( Criteria.ACCURACY_FINE );
String mocLocationProvider = lm.getBestProvider( criteria, true );
if ( mocLocationProvider == null ) {
Toast.makeText(getApplicationContext(), "No location provider found!", Toast.LENGTH_SHORT).show();
return;
}
lm.addTestProvider(mocLocationProvider, false, false,
false, false, true, true, true, 0, 5);
lm.setTestProviderEnabled(mocLocationProvider, true);
Location loc = new Location(mocLocationProvider);
Location mockLocation = new Location(mocLocationProvider);
mockLocation.setLatitude(-26.902038);
mockLocation.setLongitude(-48.671337);
mockLocation.setAltitude(loc.getAltitude());
mockLocation.setTime(System.currentTimeMillis());
lm.setTestProviderLocation( mocLocationProvider, mockLocation);
Toast.makeText(getApplicationContext(), "Working", Toast.LENGTH_SHORT).show();
}
, : " !". mocLocationProvider :
String mocLocationProvider = LocationManager.NETWORK_PROVIDER;
APP, LogCat , :
lm.setTestProviderLocation(mocLocationProvider, mockLocation);
, , .