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

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


当前回答

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

在三星Galaxy S8 + Android 8.0.0上测试

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

其他回答

在Android Studio中,运行模拟器时:

1-点击模拟器侧栏底部的设置按钮

2-进入蜂窝网络

3—选择“网络类型”

你可以使用模拟器。看看这个页面:Android模拟器。请注意下面两个论点:

-netdelay <delay> Set network latency emulation to . Default value is none. See the table in Network Delay Emulation for supported values. -netspeed <speed> Set network speed emulation to . Default value is full. See the table in Network Speed Emulation for supported values. Speeds for reference in increasing kbps: UP DOWN -------- ---------- gsm GSM/CSD 14.4 14.4 hscsd HSCSD 14.4 57.6 gprs GPRS 28.8 57.6 umts UMTS/3G 384.0 384.0 edge EDGE/EGPRS 473.6 473.6 hsdpa HSDPA 5760.0 13,980.0 lte LTE 58,000.0 173,000.0 evdo EVDO 75,000.0 280,000.0 full No limit ∞ ∞

对于mac操作系统用户,你可以使用网络链接调节器,可以从苹果下载。将其设置为mac上的AP,任何设备都可以连接它。

你可以使用facebook的开源工具ATC http://facebook.github.io/augmented-traffic-control/

我正在使用mitmproxy HTTPS代理。https://mitmproxy.org/

Mitmproxy是一个开源代理应用程序,允许拦截任何HTTP(S)客户端之间的HTTP和HTTPS连接。它允许实时监控、捕获和改变这些连接。更改请求,响应,报头,… 此外,您还可以拦截不同的请求。

例如response_delay.py:

from mitmproxy import http
from time import sleep

def response(flow: http.HTTPFlow) -> None:
    sleep(5.0)

然后执行这个注释会延迟来自服务器的所有响应:

mitmproxy --cert \*.asdf.at=./cert.pem --scripts response_delay.py

在我的应用程序中,我使用证书钉住,所以你需要添加证书(私有+公共) 猫私人。关键的公众。密钥> cert.pem

你可以在这里找到一个简单的教程。

您可以在这里找到其他脚本示例。

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/