我想测试我的应用程序的低网络连接的情况。除了站在电梯里,还有什么最好的方法呢?我试过用铝箔纸包我的手机,但没有用。

我需要在真正的设备上测试它,而不是在模拟器上。


当前回答

你也可以在真正的android设备上测试慢速互联网连接:

在三星Galaxy S8 + Android 8.0.0上测试

进入设置->连接->移动网络->,在网络模式下,你可以选择只使用2G或3G连接

其他回答

更新到Android Studio v 1.5或更高版本 正如@LouMorda在下面的评论中提到的,在最初的帖子中提到的模拟器选项卡已经在Android Studio v 1.5中被删除了。

现在他们把这些设置放在AVD管理器的模拟器设置中。 要访问这些设置:

选择“Tools -> Android -> AVD Manager” 点击编辑AVD按钮(铅笔图标) 单击“显示高级设置”按钮后,可以访问“网络设置”

下面是它的屏幕截图:

最初的发布 对于使用Android Studio IDE的人:

执行->编辑配置 选择Android应用程序->[您的应用程序] 选择模拟器选项卡 在这里,您可以更改网络速度(网速)和网络延迟(延迟)的不同值,以模拟不同的速度和延迟等

或者,您可以在其他命令行选项文本字段中输入各种参数,如@inazaruk的回答中所述。

下面的截图描述了运行配置界面的样子:

我知道现在回答这个问题有点晚了,但我希望这能帮助其他面临类似问题的人!

编辑 对于任何使用eclipse的人,请参阅下面@Abhi的回答。

在Android Studio中打开终端,进入../../Android/sdk/tools。'模拟器'可执行文件应该在这里可用。 运行。/emulator -netdelay "delay_in_millis" -avd "emulator_device_name" 例如:./emulator -netdelay 60000 -avd Nexus_5_API_21 现在构建应用程序并将其安装在模拟器中。 在应用程序中运行您的场景。

确保你有你的代码变化在应用程序设置超时你的请求和处理。

正如@VicVu Charles(或任何其他代理工具)所建议的那样,是一种更简单的方法。但我想补充的是,你也可以在你的设备上做到这一点,而不仅仅是genymotion或其他模拟器。过程是一样的:

修改您的设备/模拟器的wifi设置以使用手动代理。然后设置代理主机名和端口 A.将主机名设置为您系统的IP(使用ifconfig/ifconfig获取您pc/mac的IP) B.设置genymotion端口号(查看charles中的proxy Settings)

PS:你的设备/模拟器必须使用相同的wifi,因为你正在使用的ip很可能是私有ip。

Facebook建立了一个叫做增强交通控制的东西。GitHub页面上的简要总结:

Augmented Traffic Control (ATC) is a tool to simulate network conditions. It allows controlling the connection that a device has to the internet. Developers can use ATC to test their application across varying network conditions, easily emulating high speed, mobile, and even severely impaired networks. Aspects of the connection that can be controlled include: bandwidth latency packet loss corrupted packets packets ordering In order to be able to shape the network traffic, ATC must be running on a device that routes the traffic and sees the real IP address of the device, like your network gateway for instance. This also allows any devices that route through ATC to be able to shape their traffic. Traffic can be shaped/unshaped using a web interface allowing any devices with a web browser to use ATC without the need for a client application.

你可以在GitHub上找到它:https://github.com/facebook/augmented-traffic-control

他们还为此写了一篇博客:https://code.facebook.com/posts/1561127100804165/augmented-traffic-control-a-tool-to-simulate-network-conditions/

由于iPhone开发者选项适用于wifi绑定,你可以获得一部iOS 6及以上版本的iPhone(并已被设置为使用xcode开发),将其设置为模拟所需的网络配置文件,将你的Android设备连接到它的热点