I\'m trying to fix GPS programmatically when the GPS signal is not available. I want to do this in order to provide mock coordinates to other apps like google maps and other
What mock locations need :
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION">
Also in the android phone settings make sure you have the "Allow mock locations" checkbox ticked
locationManager.addTestProvider(mocLocationProvider, false, false,
false, false, true, true, true, 0, 5);
locationManager.setTestProviderEnabled(mocLocationProvider, true);
. Now whenever you want to send a location, call this code:
Location mockLocation = new Location(mocLocationProvider); // a string
mockLocation.setLatitude(location.getLatitude()); // double
mockLocation.setLongitude(location.getLongitude());
mockLocation.setAltitude(location.getAltitude());
mockLocation.setTime(System.currentTimeMillis());
locationManager.setTestProviderLocation( mocLocationProvider, mockLocation);
.
But this works only the first time
Because you called it one time.
I have to do a service for what I want to do
You can do this, even an AsyncTask will do
do this or not: lm.requestLocationUpdates()
Yes you have to with the mocLocationProvider
I already call more times the method setLocation(latitude,longitude) but it works(location updateding) only first time for google maps
There is no method called setLocation()
, use setTestLocation()
What actually I have to do in asynckTask
You can use a Thread, a TimerTask or anything you like. The idea is to inject location every second into the Framework.