如何禁用/启用网络,在 Android 模拟器中切换到 Wifi? [英] How to disable/enable network, switch to Wifi in Android emulator?

查看:73
本文介绍了如何禁用/启用网络,在 Android 模拟器中切换到 Wifi?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Android (http://deaconproject.org/) 开发一个需要在网络连接中断或更改时采取行动 - 即,它需要重新启动服务器连接或暂停其操作,直到网络连接可用.对于android.net.ConnectivityManager.CONNECTIVITY_ACTION",这似乎可以很好地使用 Android BroadcastReceiver.

I'm working on a Push Notifications library for Android (http://deaconproject.org/) that needs to take action if network connectivity is interrupted or changed - namely, it needs to re-initiate a server connection or pause its operation until network connectivity is available. This seems to work fine using and Android BroadcastReceiver for "android.net.ConnectivityManager.CONNECTIVITY_ACTION".

我的问题在于测试库 - 我想在各种配置条件下自动测试库对断开的网络连接或从 3G 到 WiFi 的转换的响应.问题是,我不想整天坐在模拟器旁边按 F8.

My problem is in testing the library - I would like to automatically test the library's response to a broken network connection, or a transition from 3G to WiFi, under various configuration conditions. The problem is, I don't want to sit with the emulator and hit F8 all day.

有没有办法在 jUnit 测试中以编程方式操作 Android 上的网络连接,而无需切换飞行模式?我已经尝试过通过控制台向模拟器发出命令、操纵 GSM 模式等,但是当显示屏上的电话状态发生变化时,互联网连接仍然存在.

Is there a way to programmatically manipulate network connections on Android from within a jUnit test without resorting to toggling Airplane Mode? I've already tried issuing commands to the emulator via the console, manipulating the GSM mode, etc, but while the phone state changes on the display, the Internet connection remains up.

推荐答案

在项目资源管理器"面板中右键单击项目,选择运行方式",然后选择运行配置".

Right click on project in the "Project Explorer" panel, chose "Run As" then "Run Configurations".

在模态显示窗口的左侧选择Android 应用程序",在同一窗口的右侧选择目标"选项卡.

On the left side of the modally shown window chose "Android Application" and on the right side of the same window, chose tab "Target".

在窗口底部的模拟器启动参数"部分,您有许多关于互联网连接的选项.

At the bottom of the window, in the "Emulator Launch Parameters" section you have plethora of options regarding internet connectivity.

我希望这会有所帮助.

伊戈尔

这篇关于如何禁用/启用网络,在 Android 模拟器中切换到 Wifi?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆