I want to test a GPS application I am developing in my android tablet, so I need to send to it spoof locations from a KML file loading it using DDMS. I want to use a physical device, not the emulator.
The problem is that the Emulator Control section in DDMS is disabled (grayed out) when I select my external device (the app process running) in the devices view. Insted if I select the emulator then the emulator control appears enabled but not with the physical device.
My applicaton has
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
And my physical tablet is configured with:
- USB debugging.
- Allow mock locations
I'm using SDK r20 and my tablet has android 4.0.3.
Any ideas?
Thank you very much
I've pieced together a solution to this problem.
Go to Settings->Applications->Development and select "Allow mock locations".
Add ACCESS_MOCK_LOCATION permission to AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION">
Implement a class which uses the LocationManager.addTestProvider() function. This will indicate to the application that it should use data from a file to construct new Location objects.
New Locations can then be created using the LocationManager.setTestProviderLocation() function.
// start using mock locations
try {
mockLocationCreator = new MockLocationCreator(this.getApplicationContext());
try {
mockLocationCreator.openLocationList();
mockLocationThread = new Thread(mockLocationCreator);
mockLocationThread.start();
Toast.makeText(this.getApplicationContext(),
"Mock locations are in use",
Toast.LENGTH_LONG)
.show();
} catch (IOException e) {
Toast.makeText(this.getApplicationContext(),
"Error: Unable to open / read data file",
Toast.LENGTH_LONG)
.show();
mockLocationCreator = null;
}
} catch(SecurityException e) {
Toast.makeText(this.getApplicationContext(),
"Error: Insufficient Privileges",
Toast.LENGTH_LONG)
.show();
Log.e(TAG, "unable to use mock locations, insufficient privileges", e);
}
Note: It is not possible to send mock locations to a real device from DDMS->Emulator Control->Location Controls regardless of device or manifest permissions as is incorrectly suggested here.
Sources:
Android mock location on device? - information about manifest permissions and alternative solution using the telnet command line, links and code snippets.
Using Mock Locations in Android - more verbose, contains some dead links.
LocationManager Documentation - Official Android documentation
For simple spoofing
you can use this free version but as you said in your question you want spoof
locations from a KML
file for that you have to buy pro version