我有一个x86 API23 AVD(带有Google API),它使用Android Studio 2.1.1创建,我需要发送GPS坐标。我已经广泛阅读了如何使用命令行中的“adb emu geo fix”命令或通过telnet--在验证后执行此操作,然后发送geo fix命令以及命令的纬度,经度和可选高度参数线也是如此。如何以编程方式将GPS位置发送到Android Studio 2.0 AVD
我在Mac OSX El Capitan盒子上运行我的代码。
问题是我的应用程序 - 需要输入我发送的GPS坐标的应用程序,就好像它没有获取任何数据。
如果我使用AVD本身的扩展控件来发送与SEND按钮相同的当前位置,或播放从.gpx文件加载的路由数据,那么一切正常。该应用获取GPS数据并按照预期行事。
问题是,我正在运行需要启动AVD的测试自动化(Appium,Java,TestNG),然后发送GPS数据,然后验证被测试的应用的行为与预期的一致GPS数据。
这意味着我无法手动与AVD的扩展手动控制进行交互。
我必须以编程方式完成这一切。
以下是我现在通过Telnet命令进行的操作。代码看起来基本上像这样发送只是一个“当前位置”:
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);
当上面的代码未能触发我的应用程序的预期行为,即使它出现在所有没有任何错误的工作,我用与在其上运行我的应用程序,然后启动AVD的终端使用的另一个终端发送的“当前位置”手动在Telnet行提示下列命令(认证后):
telnet localhost 5554
等待行...
然后验证通过发送身份验证令牌...
等待OK手动,则发送:
geo fix "28.4194 -81.5812"
这个命令出现在提示符下(没有错误)完美地工作,但我的应用程序显然没有得到任何GPS信息。
所以,我尝试使用上述命令的ADB版本,就像这样:
adb emu geo fix "28.4194 -81.5812"
但这也未能奏效。
同样,使用Appium自己的Android驱动程序我尝试以下(创建驱动程序后,当然):
Location currLocation = new Location(28.41936, -81.5812, 0.0);
//Set Current Location for
myDriver.setLocation(currLocation);
但司机似乎“挂”在这里。没有调试输出可以得到我。它只是......阻塞,直到事情最终超时。
而且,我也尝试了所有上述Google地图移动应用程序,但它也无法响应我发送的当前位置坐标。
所以,我卡住了!
有没有人真的有幸与PROGRAMMATICY发送“地理修复”命令到他们的应用程序下测试API23 AVD创建与Android Studio 2+?
由早于2.0版本的Android Studio创建的AVD不能用于我的目的。
任何有关我在做什么错误或可能的解决方法的反馈将不胜感激!
感谢,
沃尔夫
嗨吉尔吉森,谢谢你的好评!我会给你空的令牌技巧,试试我得到的下一个机会!但是,在我已经连接了有效的身份验证令牌后,我在代码中使用了ADB命令,但它们仍然没有工作。我本可以解决一些问题。 – Wulf
酷我很高兴你找到了发送位置和路线!也感谢lat/long的逆转。我会检查出来,也许它会让我继续使用身份验证。最后一件事,我注意到上面你在lat/long周围对adb使用了双引号,但是当我得到它的工作时,我不会将它们作为单独的值放在双引号中:adb emu geo fix 28.4194 -81.5812设置我知道这是否有助于adb – Gilgeson