DDMS not able to send location to emulator - android

DDMS is not able to send location to the emulator. I have tried sending just the location from DDMS but still the emulator is not able to receive location. The application works properly in the device but its not able to capture location data in the emulator.
I am testing on Android 2.2 emulator. Can anyone let me know what can be the issue?

Make sure your AVD has GPS support hardware set to true
Create New AVD > Hardware > New > GPS support
Value should be "yes"
Also, ensure your app is requesting location updates in some way, otherwise the emulator will just ignore any incoming locations from DDMS or the console.

I just use the android console via telnet, it always works.
Just open a command line and:
telnet localhost 5554
5554 is the port number of your emulator, it is usually that but might change, it can be on the window fram of the emulator as PORT:AVD_NAME.
You should be greeted with an Android console message.
To send positions to your device just type.
geo fix []
Two valid statements would be
geo fix -77.036519 38.896143
geo fix -77.036519 38.896143 100
Hope this helps, its not DDMS, but it works always. You can also feed it nmea sentences but I dont think you need that.

I don't know what your setup looks like, but I've had problems sending locations via DDMS using Windows XP and regional settings set to Swedish. Changing the regional settings to English(USA) solves the problem for me. I guess it has something to do with how numbers are formatted. With swedish settings numbers are formatted as 123 456 789,00 and with English(USA) as 123,456,789.00. Hope it helps

I had this problem and I resolve it by disabling the firewall,
hope it works for you.

Related

How to programmatically send GPS location to an Android Studio 2.0 AVD

I have an x86 API23 AVD (with Google APIs) created with Android Studio 2.1.1 that I need to send GPS coordinates to. I've read extensively on doing this using either "adb emu geo fix" commands from the command line, or via telnet-- after authenticating, and then sending geo fix commands along with the latitude, longitude, and optional altitude parameters at the command line as well.
I'm running my code on a Mac OSX El Capitan box.
The problem is that my application-- the app that needs to be fed the GPS coordinates that I'm sending, acts as if it is not getting any data.
If I use the Extended controls on the AVD itself to send the same current location with the SEND button, or PLAY out route data loaded from a .gpx file, then all works fine. The app gets the GPS data and behaves as expected.
The problem is that I am running test automation (Appium, Java, TestNG) that needs to launch the AVD, then send the GPS data, and then verify that my app under test behaved as expected when it was fed the correct GPS data.
This means that I cannot manually interact with the AVD's extended manual controls.
I must do this all, programmatically.
Here's what I'm doing now via Telnet commands. The code looks essentially like so for sending just a "Current Location":
import org.apache.commons.net.telnet.TelnetClient;
static TelnetClient tc = null;
public InputStream inptStream;
public PrintStream outptStream;
public String prompt = "OK";
//Instantiate the telnet client -- we use this to send geo fix commands to the emulator
tc = new TelnetClient();
//Connect, this will generate the auth_token if it does not already exist in file system
System.out.println("Trying to connect to AVD...");
tc.connect("localhost", 5554);
//Check to see if we are connected
Boolean areWeConn = tc.isConnected();
System.out.println("Are we connected?" + areWeConn);
// Get input and output stream references
System.out.println("Getting input and output streams...");
inptStream = tc.getInputStream();
outptStream = new PrintStream(tc.getOutputStream());
//wait for OK prompt
System.out.println("Waiting for the OK prompt...");
//Not including readUntil() code because it's just reading terminal output
readUntil(prompt);
//Send the auth token number
System.out.println("Sending auth token...");
outptStream.println("auth " + "3A/Yfazi3pRcvNiB");
outptStream.flush();
//wait for OK prompt
System.out.println("Waiting for the OK prompt...");
readUntil(prompt);
//Send current location for our Starting Point
System.out.println("Sending Current Location - Starting Point");
outptStream.println("geo" + "fix" + "28.4194 -81.5812");
outptStream.flush();
//Now disconnect from Telnet
System.out.println("Disconnecting from AVD...");
tc.disconnect();
//Check to see if we are still connected
Boolean stillConn = tc.isConnected();
System.out.println("Are we still connected? " + stillConn);
When the above code failed to trigger the expected behavior in my app, even though it appears to work without any errors at all, I used a terminal to launch the AVD with my app running on it, and then used another terminal to send the "current location" manually with the following commands (after authenticating) at the Telnet OK prompt:
telnet localhost 5554
Wait for OK...
Then authenticate manually by sending the auth token...
Wait for OK, then send:
geo fix "28.4194 -81.5812"
This command appeared to work perfectly at the prompt (no errors), but my app apparently didn't get any GPS information.
So, I tried using the adb version of the above command, which works like so:
adb emu geo fix "28.4194 -81.5812"
But this too failed to work.
Likewise, using Appium's own Android Driver I tried the following (after creating the driver, of course):
Location currLocation = new Location(28.41936, -81.5812, 0.0);
//Set Current Location for
myDriver.setLocation(currLocation);
But the driver appears to 'hang' here. No debug output could be gotten by me. It just... blocks, until things eventually time out.
And, I've tried all the above with the Google Maps mobile app as well, but it too fails to react to the current location coordinates that I send.
So, I am stuck!
Has anyone actually had luck with PROGRAMMATICALLY sending "geo fix" commands to their apps under test on an API23 AVD created with Android Studio 2+?
AVDs created by versions of Android Studio earlier than 2.0 cannot be used for my purposes.
Any feedback on what I'm doing wrong or possible work-arounds would be greatly appreciated!
Thanks,
Wulf
So, believe it or not, by sending longitude first, and then lattitude like so:
geo fix "-81.5812 28.4194"
The geo fix command worked for me!
Thus, the corrected code looks like this:
//Send current location for our Starting Point
System.out.println("Sending Current Location - Starting Point");
outptStream.println("geo fix -81.5812 28.4194");
outptStream.flush();
Ugh... days to figure that out, bro. Days...
I could not get the "adb emu geo fix" commands to work in my code, so I'm using the straight "geo fix" commands above and this is perfect for setting "current location".
However, "geo fix" commands do not appear to be working for me to create a route that my app draws to a map. I have a simple array of coordinates--all corrected now to give long then lat, and I play them out in a loop--but this is not working to give me a ROUTE to follow in my app.
Any ideas on how the Extended controls in Android Studio 2.0 are sending the .gpx coordinates to the emulator so that apps read this stream of info as a ROUTE rather than a single current location, marked one by one?
I hope that made sense.
****UPDATE 6/20/2016 ****
So, the above question was ill premised. Not long after posting the above query on sending "routes" instead of "current location" I discovered that an array of locations, sent one by one with "geo fix" commands does indeed work with my app and a route gets displayed on my app's map just fine! I made two big errors. First off, I was sending the ENTIRE ARRAY at once to my loop, instead of sending one location command at a time. And two, my code was not waiting for the "OK" prompt coming back on the Telnet session after each "geo fix" command was sent before sending the next "geo fix" command. Once I got these issues corrected, then things started working perfectly!
Try clearing this file: ~/.emulator_console_auth_token (or creating an empty one)
I am in the same situation. However, I discovered something that may help. In a recent release for the emulator 25.1.6, the auth command is now the required first command that must be issued when using Telnet.
http://tools.android.com/recent/emulator2516releasenotes
So to disable it you can make the ~/.emulator_console_auth_token an empty file. This seems to fix adb usage like adb emu geo fix X Y
I suspect that adb is not issuing this auth command, and would prefer to use secure method. So I am still researching that.
Also, I have not tried all scenarios, but I also enabled in the AVD Settings > Location > mode to High so it would allow use of Google Location Services.
The way I tested:
1. Cleared .emulator_console_auth_token
2. Launched emulator (API 23, x86_64 qemu)
3. Opened Google Maps App
4. It was zoomed out signaling that it had no location
5. adb emu geo fix 37 -122
6. Maps zoomed in on location.
I hope this helps.

Unable to simulate location data in Android emulator

I'm trying to test my app, which uses geolocation using the emulator. Several methods are described here. I'm going to Window->Open Perspective->DDMS, then entering lat. and long. one in Location Controls and then I hit "Send".
But it doesn't work. Instead I see the following error: Unable to send command to the emulator.
Why is this happening!?
I don't think my app is the problem because I tested with the emulator's default browser and it also cannot access location info.
Details:
OSX 10.9.4
AVD_for_Nexus_4_by_Google targeting v4.4.2
Eclipse IDE for Android Developers 23.0.2.1259578
Update:
I changed to AVD_for_Galaxy_Nexus_by_Google and it still doesn't work, but I no longer see that error. I click send and nothing happens.
Update2:
I've tested using Telnet to pass location data to the emulator, and again nothing happens. No errors. Just nothing. Urgh!
telnet localhost 5554
geo fix 50 50
It responds with OK but nothing happens. Still no location data available.
Update3:
I notice a stream of the following errors in LogCat
09-20 17:58:59.910: E/eglCodecCommon(1777): glUtilsParamSize: unknow param 0x00000b44
09-20 17:58:59.910: E/eglCodecCommon(1777): glUtilsParamSize: unknow param 0x00000bd0
09-20 17:58:59.930: E/eglCodecCommon(1777): **** ERROR unknown type 0x0 (glSizeof,72)
The app seems to be running fine, and these errors are supposedly explained here.
Update 4:
I've seen multiple suggestions to confirm that my AVD has GPS Support enabled, but this option/setting does not appear anywhere. When I open the "Android Virtual Device Manager" and then click "Edit" on one of my devices, this is what I see:
No mention of "GPS Support".
Update 5:
I checked the config.ini file for all my AVDs and they are all correctly set to hw.gps=yes. I also created an AVD using a Google API target, however I'm still having the same problem. The app loads but no location data is available, with "Location Controls" as well as telnet.
Update 6:
Following Gyebro's suggestions below... trying to load his LocationDemo app...
Here's what I see in the LogCat:
To check whether your emulator supports GPS, go to ~/.android/avd/<emulatorname>.avd/ and check config.ini and hardware-qemu.ini (if exists) they should contain:
hw.gps = yes
EDIT
You must use a Google APIs system image. You should set Google APIs - API Level 1# as target
End of EDIT
Assuming this is so, and Location is enabled in your emulator, run this test application in your emulator: LocationTest demo, for details see the Dev docs on Retrieving the Current Location
This sample implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener and LocationListener. And also checks for Google Play Services before connecting with the LocationClient (that's why we needed a Google Emulator image.) (See MainActivity.java)
After you start the app, you should see the Location icon in the status bar. Also verify, that the GP Services are present and the LocationClient is connected in the Log.
D/LocationTest﹕ Google Play services is available.
D/LocationTest﹕ LocationClient: Connected
After sending geo fix 66 80 using telnet (should respond with OK) or other valid coordinates using DDMS, you should see:
D/LocationTest﹕ Location changed!
If you are still lost with this approach, another way to simulate locations is to create a Mock Location Provider app.
You really should use GENYMOTION it offers a GPS feature in which u set the location coordinates, plus it's faster than the default emulator and works fine in almost every OS, heres the Docus on how to apply that GPS stuff here inside that page look for "GPS widget". Good luck.
Heres a shot from that window
I tried with latest SDK and adb tools, i see the same problem with Google Maps and web browser based location (maps.google.com). I used adb command line as well as telnet methods to set the location. Also verified my .avd file has hw.gps=yes (which is set by default). I even tried with older Google API images. I made sure to try out different accuracy levels too - device only, high accuracy etc. I notice lot of graphics rendering issues and quite a few opengl error messages in logcat, similar to ones you see.
I did get google maps app to work on Android emulator using mock locations feature. You can use mock locations on a real device too, which i prefer for its performance. For details on how to use mock location please see this.. Download the zip file which has LocationProvider project , that lets you simulate different location and movement scenarios.
so you can pick:
Use a physical android device with mock locations feature
If you want to use emulator, try with mock locations
I had success with genymotion too, you can set any location you want from command line genyshell that comes with genymotion
genyshell.exe -c "gps setstatus enabled"
genyshell.exe -c "gps setlatitude 30.3077609"
genyshell.exe -c "gps setlongitude -97.7534014"
device is preferable for performance reasons.
Update:
I tested with LocationTest demo by gyebro and it works when i set the location params using telnet. So the problem seems to be with google maps or browser and not with emulator or adb tools.
Did you tried with free version of Genymotion? It works as a real device connected by USB, and it can create GPS positions as you need. I know that this is not a solution for your AVD problem but AVD is in generally a poor solution to Android testing on emulators.
It's free if you want to test this function specifically.
I was running through the same errors. The problem was that the AVD DDMS uses a comma instead of a dot in their location coordinates.
Use LAT: -16,691534 LNG: -49,266185 something like this and you will be fine!

When I try to send a location update to the emulator I get an error message

When I am in the emulator control view in the DDMS I am attempting to send a Mock Location to my emulator. However when I try this I get the following error message, "Unable to send command to the emulator". I cannot understand why this is not working as it was fine yesterday and I havent made any changes to my application. Please help?
I was facing same problem. After restarting process of adb.exe from task manager it worked.
If you use mobile device for checking results, I think in your code, you would have mentioned the NETWORK_PROVIDER in location manager. If it is, then change it to GPS_PROVIDER and dont forget to add the permissions in your manifest file(android.permission.ACCESS_FINE_LOCATION). And now send the command through emulator control. it will work.

Spoof or fake location on Android phone

I've been trying to get this to work for a few days without success. Basically, I'm writing a small test app to make the phone report it's position as somewhere else using addTestProvider and setTestProviderLocation etc. Basically it looks fine and appears to report its location as having changed, however Google Maps etc. seems to still be querying the real GPS provider. Does anyone have any ideas how to get around this?
This isn't an app that will actually be used for anything, it's just really to satisfy my own curiosity and gain an understanding.
Thanks in advance.
You need to first allow your application to use Mock locations by adding the following to the manifest xml:
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
On your phone, ensure 'Mock Locations' are enabled by selecting the “Allow mock locations” option under the Settings -> Applications -> Development menu.
And then use a mock location provider to give fake locations (e.g. by reading data off a file/db)
Alternatively you can telnet into your phone and mock the location (again you need permission and mock locations enabled on your phone):
$ telnet localhost 5554
Android Console: type 'help' for a list of commands
OK
geo fix -82.411629 28.054553
OK

How to emulate GPS location in the Android Emulator?

I want to get longitude and latitude in Android emulator for testing.
Can any one guide me how to achieve this?
How do I set the location of the emulator to a test position?
You can connect to the Emulator via Telnet. You then have a Emulator console that lets you enter certain data like geo fixes, network etc.
How to use the console is extensively explained here.
To connect to the console open a command line and type
telnet localhost 5554
You then can use the geo command to set a latitude, longitude and if needed altitude on the device that is passed to all programs using the gps location provider. See the link above for further instructions.
The specific command to run in the console is
geo fix <longitude value> <latitude value>
I found this site useful for finding a realistic lat/lng: http://itouchmap.com/latlong.html
If you need more then one coordinate you can use a kml file with a route as well it is a little bit described in this article. I can't find a better source at the moment.
No one here mentioned the built in solution of the emulator itself, so for future visitors, I'd like to share it with visuals.
First, run your Android Emulator and click on the menu button (3 dots) shown below:
Then from the left pane, select Location and change the coordinates according to your needs. After pressing Send button, changes will immediately take effect (I recommend you to open up Google Maps for better understanding).
Android Studio Version: 2.3.3
In addition, to make your different locations coming to your application in real time, you can use GPX file. It's very easy to create this file from Google Map direction link:
Go to google map, choose a location, then press "Directions" and enter the second location.
After route is created, copy a link from the browser
Go to this website: https://mapstogpx.com and paste the link to "Let's Go" box
Press the "Let's Go" button and GPX file will be downloaded
Use "Load GPS/KML" button to load the created file to your emulator, choose speed, and press green play button on the bottom. Locations will be sent in real time as shown on the picture below.
I was looking for a better way to set the emulator's GPS coordinates than using geo fix and manually determining the specific latitude and longitude coordinates.
Unable to find anything, I put together a little program that uses GWT and the Google Maps API to launch a browser-based map tool to set the GPS location in the emulator:
android-gps-emulator
Hopefully it can be of use to help others who will undoubtedly stumble across this difficulty/question as well.
If you're using Eclipse, go to Window->Open Perspective->DDMS, then type one in Location Controls and hit Send.
For Android Studio users:
run the emulator,
Then, go to Tools -> Android ->Android device monitor
open the Emulator Control Tab, and use the location controls group.
Sorry for the NecroPost, but after following some of the suggestions on this question, I set my location to Alaska. However, my device was still showing to be in Mountain View, California (Google's HQ?). So here's how I did a fix:
1) Go to the location settings:
2) Set your test location. I chose Alaska.
3) Google "My current location" and click on the map circled in the picture.
Note that even though I set location as Alaska, my Virtual Device still thinks it's in Mountain View, California.
4) Click on this location Icon
Your location should now be updated on your device.
You can verify by Googling "My current location" again.
If anyone experienced this same issue, I hope my solution helped you.
Assuming you've got a mapview set up and running:
MapView mapView = (MapView) findViewById(R.id.mapview);
final MyLocationOverlay myLocation = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocation);
myLocation.enableMyLocation();
myLocation.runOnFirstFix(new Runnable() {
public void run() {
GeoPoint pt = myLocation.getMyLocation();
}
});
You'll need the following permission in your manifest:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
And to send mock coordinates to the emulator from Eclipse, Go to the "Window" menu, select "Show View" > "Other" > "Emulator control", and you can send coordinates from the emulator control pane that appears.
For the new emulator:
http://developer.android.com/tools/devices/emulator.html#extended
Basically, click on the three dots button in the emulator controls (to the right of the emulator) and it will open up a menu which will allow you to control the emulator including location
1. Android Studio users.
After running the emulator goto Tools->Android->Android device monitor
Click the Emulator Control Tab change from the location controls group.
2. Eclipse users.
First In Eclipse In Menu Select "Window" then Select "Open Perspective" then Select "DDMS".
i.e Window->Open Prespective->DDMS.
You will see on Left Side Devices Panel and on Right Side you will see different tabs.
Select "Emulator Control" Tab.
At bottom you will see Location Controls Panel.
Select "Manual" Tab.
Enter Longitude and Latitude in Textboxs then Click Send Button.
It will send the position to you emulator and the application.
3. Using telnet.
In the run command type this.
telnet localhost 5554
If you are not using windows you can use any telnet client.
After connecting with telnet use the following command to send your position to emulator.
geo fix long lat
geo fix -121.45356 46.51119 4392
4. Use the browser based Google maps tool
There is a program that uses GWT and the Google Maps API to launch a browser-based map tool to set the GPS location in the emulator:
android-gps-emulator
Finally with the latest release of Android Studio 4 and his new Emulator update 10/23/2019 it become easier.
Start your emulator and go to emulator parameters ... > in "Routes" tab you can choose two points on the map from/to and start a new route with an adjustable playback speed that can go to more than 1000km/h!
The following solution worked for me - open command line and write:
adb emu geo fix [longtitude] [latitude]
Using the "geo" command in the emulator console
To send mock location data from the command line:
Launch your application in the Android emulator and open a terminal/console in your SDK's /tools directory.
Connect to the emulator console:
telnet localhost 5555 (Replace 5555 with whatever port your emulator is running on)
Send the location data:
* geo fix to send a fixed geo-location.
This command accepts a longitude and latitude in decimal degrees, and an optional altitude in meters. For example:
geo fix -121.45356 46.51119 4392
I wrote a python script to push gps locations to the emulator via telnet. It defines a source and a destination location. There is also a time offset which lets you control how long coordinates will be pushed to the device. One location is beeing pushed once a second.
In the example below the script moves from Berlin to Hamburg in 120 seconds. One step/gps location per second with random distances.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import telnetlib
from time import sleep
import random
HOST = "127.0.0.1"
PORT = 5554
TIMEOUT = 10
LAT_SRC = 52.5243700
LNG_SRC = 13.4105300
LAT_DST = 53.5753200
LNG_DST = 10.0153400
SECONDS = 120
LAT_MAX_STEP = ((max(LAT_DST, LAT_SRC) - min(LAT_DST, LAT_SRC)) / SECONDS) * 2
LNG_MAX_STEP = ((max(LNG_DST, LNG_SRC) - min(LNG_DST, LNG_SRC)) / SECONDS) * 2
DIRECTION_LAT = 1 if LAT_DST - LAT_SRC > 0 else -1
DIRECTION_LNG = 1 if LNG_DST - LNG_SRC > 0 else -1
lat = LAT_SRC
lng = LNG_SRC
tn = telnetlib.Telnet(HOST, PORT, TIMEOUT)
tn.set_debuglevel(9)
tn.read_until("OK", 5)
tn.write("geo fix {0} {1}\n".format(LNG_SRC, LAT_SRC))
#tn.write("exit\n")
for i in range(SECONDS):
lat += round(random.uniform(0, LAT_MAX_STEP), 7) * DIRECTION_LAT
lng += round(random.uniform(0, LNG_MAX_STEP), 7) * DIRECTION_LNG
#tn.read_until("OK", 5)
tn.write("geo fix {0} {1}\n".format(lng, lat))
#tn.write("exit\n")
sleep(1)
tn.write("geo fix {0} {1}\n".format(LNG_DST, LAT_DST))
tn.write("exit\n")
print tn.read_all()
In Linux where communication ports are blocked. navigate the terminal to platform-tools folder inside android sdk and fire this command:
./adb -s #{device_name} emu geo fix #{longitude} #{latitude}
In Mac, Linux or Cygwin:
echo 'geo fix -99.133333 19.43333 2202' | nc localhost 5554
That will put you in Mexico City. Change your longitude/latitude/altitude accordingly. That should be enough if you are not interested in nmea.
I use eclipse plug DDMS function to send GPS.
See Obtaining User Location
Look under Providing Mock Location Data. You will find the solution for it.
First go in DDMS section in your eclipse
Than open emulator Control ....
Go To Manual Section
set lat and long and then press Send Button
I was trying to set the geo fix through adb for many points and could not get my app to see any GPS data. But when I tried opening DDMS, selecting my app's process and sending coordinates through the emulator control tab it worked right away.
Dalvik Debug Monitor > Select Emulator > Emulator Control Tab > Location Controls.
DDMS -- android_sdk/tools/ddms OR android_sdk/tools/monitor
If you are using eclipse then using Emulator controller you can manually set latitude and longitude and run your map based app in emulator
If you're using Android Studio (1.3):
Click on Menu "Tools"
"Android"
"Android device monitor"
click on your current Emulator
Tab "Emulator Control"
go to "Location Controls" and enter Lat and Lon
Just make Alberto Gaona's answer into one line
token=$(cat ~/.emulator_console_auth_token); cat <(echo -e "auth $token \n geo fix 96.0290791 16.9041016 \n exit") - | nc localhost 5554
5554 is the emulator port number shown in adb devices.
It would have been better if adb emu work.
Go to Extended controls in emulate. After You can then set the location for the emulate by searching or dragging the map to the location you want to set.
Finally Click on SET LOCATION button to save.
If the above solutions don't work. Try this:
Inside your android Manifest.xml, add the following two links OUTSIDE of the application tag, but inside your manifest tag of course
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" ></uses-permission>
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
I was unable to get a GPS fix on the emulator when emulator was running Android image without Google APIs. As soon as I changed the image to contain Google APIs all of the here mentioned ways to get a GPS fix worked.
Make sure you select an image with Google APIs when creating AVD.
The already mentioned multiple times answer to use the shell command "geo fix..." is the correct answer.
But in case you use LocationClient.getLastLocation() to retrieve your data it is worth to mention that it will not work at first. The LocationClient class uses the Google Play Service to retrieve the coordinates.
For me this started working after running the emulators maps app once. During the first start you are asked to allow google apps access to your location, which I guess does the trick.
For a project of my own, I developed an online service which can provide simulated location to the Android emulator.
It uses geo nmea rather than geo fix which allows it to set speed, course, precise time etc. in addition to just lat/lon.
The service requires the nc (netcat) command line utility and nothing else.
http://www.kisstech.ch/nmea/
You can use an emulator like genymotion which gives you the flexibility to emulate your present GPS location, etc.
There is a plugin for Android Studio called “Mock Location Plugin”.
You can emulate multiple points with this plugin.
You can find a detailed manual of use in this link: Android Studio. Simulate multiple GPS points with Mock Location Plugin

Categories

Resources