views:

2351

answers:

7

How can I mock my location on a physical device (Nexus One)? I know you can do this with the emulator in the Emulator Control panel, but this doesn't work for a physical device.

A: 

If you use this phone only in development lab, there is a chance you can solder away GPS chip and feed serial port directly with NMEA sequences from other device.

tomash
Why the haters? This answer is awesomely hard core.
quixoto
A: 

For desktop computers you can create/install drivers that emulate a GPS device/serial port device for the purpose of doing this kind of testing. Perhaps you could create or find something similar for android.

AaronLS
+3  A: 

I found this example with some Googling - it sends data directly to the LocationManager.

Android location provider mock

Andrew Koester
+6  A: 

Andrews link points in the right direction it seems the only way to do is to use a mock location provider. You have to enable mock locations in the development panel in your settings and add

   <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /> 

to your manifest. Now you can go in your code and create your own mock location provider and set the location of this provider like explained in Andrews link

Janusz
+2  A: 

You can use the Location Services permission to mock location...

"android.permission.ACCESS_MOCK_LOCATION"

and then in your java code,

// Set location by setting the latitude, longitude and may be the altitude...
String[] MockLoc = str.split(",");
Location location = new Location(mocLocationProvider);            
Double lat = Double.valueOf(MockLoc[0]);
location.setLatitude(lat);
Double longi = Double.valueOf(MockLoc[1]);
location.setLongitude(longi);
Double alti = Double.valueOf(MockLoc[2]);
location.setAltitude(alti);
Vishwanath
+1  A: 

I wish I had my cable handy. I know you can telnet to the emulator to change it's location

$ telnet localhost 5554
Android Console: type 'help' for a list of commands
OK
geo fix -82.411629 28.054553
OK

I cannot remember if you can telnet to your device, but I think you can. I hope this helps.

You'll need adb (android debugging bridge) for this (CLI).

Tim Green
you get a permission denied to everything you send as a command to the console of your device. Maybe it is possible with a terminal application but I think that requires root access
Janusz
Just so we're on the same page: you're not talking about "adb shell" are you? What I'm talking about is different, this is something setup that allows you to set android-specific parameters.I know, for example, you can setup port forwarding (i.e. localhost:1234 goes to phone:1234) without root access, so you can setup a SOCKS proxy and tunnel via a cable w/o root.
Tim Green
You can use adb forward tcp:6000 tcp:23 to forwward port 6000 on your machine to port 23 on the device but I wasn't able to connect even if the port is shown as open. Using a telnet client on the device and connecting to localhost also fails
Janusz
A: 

I use both