简体   繁体   English

通过命令行启动无数据的Android仿真器

[英]Launch Android Emulator with No Data via Command Line

I'm trying to figure out how to launch an emulator with no data connection or airplane mode, either one will work. 我试图弄清楚如何在没有数据连接或飞行模式的情况下启动仿真器,无论哪种都可以。 Im testing my application against data loss, however I need this to be atomized. 我正在测试我的应用程序以防数据丢失,但是我需要对此进行细化。 Therefore I'm trying either to launch the emulator with no data via command line, or write bash script to launch emulator, turn data off, then run Unit Test. 因此,我正在尝试通过命令行启动没有数据的模拟器,或者编写bash脚本以启动模拟器,关闭数据,然后运行单元测试。

RESOLVED - Per Recommendations 解决-根据建议

#! /usr/bin/expect

set timeout 10
spawn telnet localhost 5554
expect "OK"
send "gsm data off\n"
send "quit\n"

The quick and dirty way to do it could be to make an app that starts at boot and turns data off, then run the emulator and install the app. 快速而肮脏的方法可能是制作一个在启动时启动并关闭数据的应用程序,然后运行模拟器并安装该应用程序。 This does have potential for inconsistency however. 但是,这确实有可能导致不一致。

The other thing you can do to leave just the emulator without a network is to telnet into the emulator and turn data off. 您可以做的另一件事就是仅使仿真器不具有网络,那就是通过telnet进入仿真器并关闭数据。 To automate it, I made a simple (and crude) example using a batch file and vbscript to feed telnet the commands since my work machine is running Windows. 为了使它自动化,我做了一个简单(粗略)的示例,使用批处理文件和vbscript向telnet输入命令,因为我的工作机运行的是Windows。

The batch file: 批处理文件:

@echo off
emulator -avd YOURAVDNAMEHERE
timeout /t 10
telnet_turn_data_off.vbs

telnet_turn_data_off.vbs : telnet_turn_data_off.vbs

set oShell=CreateObject("WScript.Shell")

oShell.Run "telnet localhost 5554", 9
WScript.sleep 500

oShell.Sendkeys "gsm data off{ENTER}"
WScript.sleep 500

oShell.Sendkeys "gsm voice off{ENTER}"
WScript.sleep 500

oShell.Sendkeys "quit{ENTER}"
WScript.sleep 500

oShell.Sendkeys "quit{ENTER}"
WScript.sleep 500

If running on Linux or Mac OS, expect should be able to script telnet (as seen by the edit to the question). 如果在Linux或Mac OS上运行,则期望能够编写telnet脚本(如问题的编辑所示)。

It is also worth noting that on older emulators (eg 2.2), turning data off might not do anything . 还值得注意的是,在较旧的仿真器(例如2.2)上, 关闭数据可能无济于事 My above example was tested with a 4.2 emulator and it appeared to cut off data properly. 我上面的示例在4.2模拟器上进行了测试,看来可以正确切断数据。

I typically use physical hardware for testing instead of emulators, but if you can't find an option to enable airplane mode you could simply disconnect your computer from the internet before launching the emulator. 我通常使用物理硬件而不是仿真器进行测试,但是,如果找不到启用飞行模式的选项,则可以在启动仿真器之前简单地断开计算机与Internet的连接。 No internet for your computer = no internet for your emulator. 您的计算机没有互联网=仿真器没有互联网。

Use This Following steps.. 使用以下步骤。

Go to Eclipse 转到Eclipse

Window->show view->other->android->Devices now select your running emulator and Again 窗口->显示视图->其他-> android->设备现在选择正在运行的模拟器并再次

Go to, 去,

Window->show view->other->android->Emulator Control Now in that..set Data to Unregister from Home 窗口->显示视图->其他-> android->仿真器控制

From Device and Emulator 从设备和仿真器

In Device or Emulator Go to, 在“设备或仿真器”中,转到

Setting -> Wireless & networks -> Airplane Mode -> ok 设置->无线和网络->飞行模式->确定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM