如何将 AVD(模拟器)置于离线模式?

发布于 2024-09-28 19:04:04 字数 262 浏览 9 评论 0原文

我想测试当用户处于无信号区域或手机处于飞行模式时我的应用程序的行为。

-> 如何将 Android 虚拟设备置于离线模式(无法连接到互联网)?

我尝试过以下操作:

  • 通过 AVD 设置激活飞行模式:令人惊讶的是,这不起作用(在飞行模式下仍然可以浏览互联网!)

  • 禁用我的电脑上的网络连接:这显然有效,但并不令人满意,因为我在测试应用程序时需要互联网

I would like to test the behavior of my application when the user is in a no-signal zone or when his phone is in flight mode.

-> How do I put an Android Virtual Device into offline mode (where no connection to the internet is possible) ?

I have tried the following:

  • Activating flight mode via the AVD settings: surprisingly, this does NOT work (browsing the internet is still possible in flight mode!)

  • Disabling the network connection on my PC: this obviously works, but is not satisfactory as I need Internet when I am testing my app

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

删除→记忆 2024-10-05 19:04:04

无线网络:

$ adb shell svc wifi enable
$ adb shell svc wifi disable

移动数据:

$ adb shell svc data enable
$ adb shell svc data disable

WIFI:

$ adb shell svc wifi enable
$ adb shell svc wifi disable

MOBILE DATA:

$ adb shell svc data enable
$ adb shell svc data disable
深者入戏 2024-10-05 19:04:04

我看到了所有同样的问题。 DDMS 并没有完全消灭它。 F8也没有。在模拟器内打开飞行模式也不会。我们都应该为 2009 年登录的此问题加注星标。

I'm seeing all the same problems. DDMS doesn't fully kill it. Neither does F8. And neither does turning on airplane mode inside the emulator. We should all probably star this issue someone logged in 2009.

傲世九天 2024-10-05 19:04:04

我找到了一个可行的解决方案。在 Android 6.0 和 7.0 模拟器上进行了测试,但应该适用于其他模拟器。

网络关闭:

adb shell ifconfig eth0 down

网络开启:

adb shell ifconfig eth0 up

如果出现“权限被拒绝”错误,请以 root 身份重新启动 adb 守护进程:

adb root

然后重试。

I found a working solution. Tested on Android 6.0 an 7.0 emulators, but should work on others.

Network down:

adb shell ifconfig eth0 down

Network up:

adb shell ifconfig eth0 up

If you get a "Permission denied" error, restart adb daemon as root:

adb root

and try again.

一笑百媚生 2024-10-05 19:04:04

您只需在模拟器窗口中按 F8,它就会根据以下内容关闭蜂窝网络: http: //developer.android.com/guide/developing/tools/emulator.html。但我测试了一下,它也不起作用!只有一条消息说没有互联网连接,但它实际上可以工作......

You should just press F8 in emulator window, it toggle off cell networking according to: http://developer.android.com/guide/developing/tools/emulator.html. But I test it and it is not working too! There is only message that there is no internet connection but it actually works...

姜生凉生 2024-10-05 19:04:04

我所做的就是进入“窗口”菜单,选择“打开透视图->其他”打开 DDMS 透视图。在 DDMS 透视图中,您有一个“模拟器控制”视图,您可以在其中调整延迟、漫游,还可以为其提供不同的电话和数据状态。因此,按照此过程获取模拟器视图,然后转到“数据”下拉列表并选择“拒绝”选项。

All I do is go into the Window menu, select 'open perspective->other' open the DDMS perspective. Inside the DDMS perspective you have an 'Emulator Control' view where you can adjust latency, roaming, you can give it different telephone and data states. So following this procedure to get the Emulator view, you then go to 'Data' drop down and select the 'Denied' option.

他不在意 2024-10-05 19:04:04

当我将语音和数据调整为“未注册”而不是“拒绝”时,我发现在“模拟器控制”视图中对我有用。现在我终于让 AVD 离线了,同时我仍然可以发布这个答案。

I found in my 'Emulator Control' view when I adjust Voice and Data to "unregistered" not "denied" works for me. Now I finally got the AVD offline for network while I can still post this answer.

千寻… 2024-10-05 19:04:04

不要在 Android 模拟器中使用飞行模式(效果不太好),而是在测试时关闭系统的网络连接。即以太网连接或Wi-fi 的交换机。对我来说效果很好。

Instead of using Airplane mode in the Android emulator ( which does not work too well ) , switch off the network connectivity to your system while testing. That is , switch of the Ethernet connectivity or Wi-fi . Worked well for me.

So尛奶瓶 2024-10-05 19:04:04

老问题,但我找到了解决方案:

  1. 打开命令行:CTRL+R > cmd
  2. 更改为 android 工具文件夹

    cd C:\Program Files\Android\android-sdk\tools

  3. 使用错误的 DNS 服务器运行模拟器。将 2.3.3 更改为您的 AVD 的名称。 @ 使其开始:

    emulator.exe @2.3.3 -dns-server 127.0.0.1

查看手册以获取更多命令行选项

Old questions, but I found a solution:

  1. Open a command line: CTRL+R > cmd
  2. Change to android tools folder

    cd C:\Program Files\Android\android-sdk\tools

  3. Run the emulator with a false DNS server. Change 2.3.3 to the the name of your AVD. The @ makes it start:

    emulator.exe @2.3.3 -dns-server 127.0.0.1

Check the manual for more command line options.

你穿错了嫁妆 2024-10-05 19:04:04

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) 上也是如此

,但也许这对某人有用......

One comment of the issue mentioned by James Koch says that there is an workaround:

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

BUT:

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 !

-> Same for me on Windows Vista, SDK rev 19 and platform 10 (2.3.3)

But perhaps that's usable for somebody...

美人骨 2024-10-05 19:04:04

最后说一下这个方法怎么样。

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 进行测试。

Finally, how about this approach.

android-sdks/tools/emulator -avd [AVD name goes here] -qemu -net nic,vlan=0 -net user,vlan=1

Actually, this is a trick because the following crashes my emulator:

android-sdks/tools/emulator -avd [AVD name goes here] -qemu -net none

Tested with Android emulator V21.0 on Debian.

我的黑色迷你裙 2024-10-05 19:04:04

我发现 @Marco C. 的答案有效,但我也发现我的 AVD 设置也允许非常轻松地执行此操作。

在侧边栏中,单击底部的三点图标:

在此处输入图像描述

然后,将您的蜂窝网络设置“信号强度”和“数据状态”分别调整为“无”和“拒绝”,如下图所示:

在此处输入图像描述

I found that the answer from @Marco C. worked, but I also found that my AVD settings allowed for doing this very easily as well.

In the sidebar, click the triple dot icon all the way at the bottom:

enter image description here

Then, adjust your cellular settings, "Signal Strength" and "Data Status" to "none" and "denied" respectively, as shown in this image:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文