当用户处于无信号区域或手机处于飞行模式时,我想测试我的应用程序的行为。
- >如何将Android虚拟设备置于离线模式(无法连接到互联网)?
我尝试过以下方法:
我看到了同样的问题。 DDMS没有完全杀死它。 F8也不是。也没有在模拟器内打开飞机模式。我们都应该为2009年登陆的某人加入this issue。
最后,这种方法怎么样。
android-sdks/tools/emulator -avd [AVD name goes here] -qemu -net nic,vlan=0 -net user,vlan=1
实际上,这是一个技巧,因为以下崩溃我的模拟器:
android-sdks/tools/emulator -avd [AVD name goes here] -qemu -net none
在Debian上使用Android模拟器V21.0进行测试。
无线上网:
$ adb shell svc wifi enable
$ adb shell svc wifi disable
移动数据:
$ adb shell svc data enable
$ adb shell svc data disable
我找到了一个有效的解决方在Android 6.0和7.0模拟器上测试过,但应该在其他模拟器上运行。
网络下来:
adb shell ifconfig eth0 down
网络化:
adb shell ifconfig eth0 up
如果您收到“权限被拒绝”错误,请以root身份重新启动adb守护程序:
adb root
然后再试一次。
你应该只在模拟器窗口按F8,它根据:http://developer.android.com/guide/developing/tools/emulator.html关闭单元网络。但我测试它,它也没有工作!只有消息说没有互联网连接但实际上有效...
我所做的就是进入Window菜单,选择'open perspective-> other'打开DDMS透视图。在DDMS透视图中,您有一个“模拟器控制”视图,您可以在其中调整延迟,漫游,您可以为其提供不同的电话和数据状态。因此,按照此过程获取模拟器视图,然后转到“数据”下拉菜单并选择“拒绝”选项。
当我将语音和数据调整为“未注册”而非“拒绝”对我有用时,我在“模拟器控制”视图中找到了。现在我终于让AVD离线了网络,而我仍然可以发布这个答案。
不要在Android模拟器中使用飞行模式(效果不佳),在测试时关闭与系统的网络连接。也就是说,切换以太网连接或Wi-Fi。对我来说工作得很好。
老问题,但我找到了解决方案:
cmd
cd C:\Program Files\Android\android-sdk\tools
2.3.3
更改为您的AVD名称。 @使它开始:
emulator.exe @2.3.3 -dns-server 127.0.0.1
查看手册以获取更多命令line options。
James Koch提到的这个问题的一个评论说有一个解决方法:
Comment 15 by iscy%[email protected], Jul 8, 2011 Finally found a work around for this issue: telnet localhost 5554 // Connects to the emulator qemu monitor // Enter in the QEmu functionalities info network // List the network adapter "user.0" is usually the name set_link user.0 down // Shut the network down set_link user.0 up // Re-enable networking
但:
Comment 16 by [email protected], Sep 6, 2011 This work around doesn't work for me on MacOS 10.7.1 and SDK rev 12 (with platform 2.2, 2.1 and 2.3.3) ... ... qemu monitor KO: internal error: could not detach from console !
- >在Windows Vista,SDK rev 19和平台10(2.3.3)上对我来说相同
但也许那对某人有用......