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


i have x86 api23 avd (with google apis) created android studio 2.1.1 need send gps coordinates to. i've read extensively on doing using either "adb emu geo fix" commands command line, or via telnet-- after authenticating, , sending geo fix commands along latitude, longitude, , optional altitude parameters @ command line well.

i'm running code on mac osx el capitan box.

the problem application-- app needs fed gps coordinates i'm sending, acts if not getting data.

if use extended controls on avd send same current location send button, or play out route data loaded .gpx file, works fine. app gets gps data , behaves expected.

the problem running test automation (appium, java, testng) needs launch avd, send gps data, , verify app under test behaved expected when fed correct gps data.

this means cannot manually interact avd's extended manual controls.

i must all, programmatically.

here's i'm doing via telnet commands. code looks sending "current location":

import org.apache.commons.net.telnet.telnetclient;  static telnetclient tc = null;      public inputstream inptstream;     public printstream outptstream;     public string prompt = "ok";  //instantiate telnet client -- use send geo fix commands emulator             tc = new telnetclient();  //connect, generate auth_token if not exist in file system                 system.out.println("trying connect avd...");                 tc.connect("localhost", 5554);  //check see if connected                 boolean areweconn = tc.isconnected();                 system.out.println("are connected?" + areweconn);  // input , output stream references                 system.out.println("getting input , output streams...");                 inptstream = tc.getinputstream();                 outptstream = new printstream(tc.getoutputstream());                  //wait ok prompt                 system.out.println("waiting ok prompt...");                 //not including readuntil() code because it's reading  terminal output                 readuntil(prompt);                  //send auth token number                 system.out.println("sending auth token...");                 outptstream.println("auth " + "3a/yfazi3prcvnib");                 outptstream.flush();                  //wait ok prompt                 system.out.println("waiting ok prompt...");                 readuntil(prompt);                  //send current location our starting point                 system.out.println("sending current location - starting point");                 outptstream.println("geo" + "fix" + "28.4194 -81.5812");                 outptstream.flush();   //now disconnect telnet                 system.out.println("disconnecting avd...");                 tc.disconnect();  //check see if still connected                 boolean stillconn = tc.isconnected();                 system.out.println("are still connected? " + stillconn); 

when above code failed trigger expected behavior in app, though appears work without errors @ all, used terminal launch avd app running on it, , used terminal send "current location" manually following commands (after authenticating) @ telnet ok prompt:

telnet localhost 5554 

wait ok...

then authenticate manually sending auth token...

wait ok, send:

geo fix "28.4194 -81.5812" 

this command appeared work @ prompt (no errors), app apparently didn't gps information.

so, tried using adb version of above command, works so:

adb emu geo fix "28.4194 -81.5812" 

but failed work.

likewise, using appium's own android driver tried following (after creating driver, of course):

location currlocation = new location(28.41936, -81.5812, 0.0);              //set current location             mydriver.setlocation(currlocation); 

but driver appears 'hang' here. no debug output gotten me. just... blocks, until things time out.

and, i've tried above google maps mobile app well, fails react current location coordinates send.

so, stuck!

has had luck programmatically sending "geo fix" commands apps under test on api23 avd created android studio 2+?

avds created versions of android studio earlier 2.0 cannot used purposes.

any feedback on i'm doing wrong or possible work-arounds appreciated!

thanks,

wulf

so, believe or not, sending longitude first, , lattitude so:

geo fix "-81.5812 28.4194" 

the geo fix command worked me!

thus, corrected code looks this:

//send current location our starting point                 system.out.println("sending current location - starting point");                 outptstream.println("geo fix -81.5812 28.4194");                 outptstream.flush();  

ugh... days figure out, bro. days...

i not "adb emu geo fix" commands work in code, i'm using straight "geo fix" commands above , perfect setting "current location".

however, "geo fix" commands not appear working me create route app draws map. have simple array of coordinates--all corrected give long lat, , play them out in loop--but not working give me route follow in app.

any ideas on how extended controls in android studio 2.0 sending .gpx coordinates emulator apps read stream of info route rather single current location, marked 1 one?

i hope made sense.

****update 6/20/2016 ****

so, above question ill premised. not long after posting above query on sending "routes" instead of "current location" discovered array of locations, sent 1 one "geo fix" commands indeed work app , route gets displayed on app's map fine! made 2 big errors. first off, sending entire array @ once loop, instead of sending 1 location command @ time. , two, code not waiting "ok" prompt coming on telnet session after each "geo fix" command sent before sending next "geo fix" command. once got these issues corrected, things started working perfectly!