模拟 Android 的低网络连接

发布于 2024-11-29 08:20:29 字数 1539 浏览 3 评论 0 原文

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

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

发布评论

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

评论(27

地狱即天堂 2024-12-06 08:20:29

这听起来可能有点疯狂,但微波炉可以起到微波炉屏蔽的作用。因此,将您的设备放入微波炉内(设备在微波炉内时请勿打开微波炉!)将导致您的信号强度显着下降。这绝对胜过站在电梯里……

This may sound a little crazy, but a microwave oven serves as a microwave shield. Therefore, putting your device inside a microwave oven (DO NOT turn on the microwave oven while your device is inside!) will cause your signal strength to drop significantly. It definitely beats standing inside an elevator...

或十年 2024-12-06 08:20:29

您可以为此使用模拟器。看一下此页面:Android 模拟器。注意接下来的两个参数:

  1. -netdelay

    <块引用>

    将网络延迟仿真设置为 .默认值为无。看
    网络延迟仿真中的表格了解支持的值。

  2. -netspeed <速度>

    <块引用>

    将网络速度模拟设置为 .默认值为满。看
    网络速度仿真中的表格了解支持的值。

    增加 kbps 时的参考速度:

    <前><代码> 向上 向下
    -------- ----------
    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/EGPRS 473.6 473.6
    HSDPA HSDPA 5760.0 13,980.0
    LTE LTE 58,000.0 173,000.0
    电动汽车 EVDO 75,000.0 280,000.0
    满 无限制 无穷大 无穷大

You can use emulator for this. Take a look at this page: Android Emulator. Pay attention to next two arguments:

  1. -netdelay <delay>

    Set network latency emulation to . Default value is none. See
    the table in Network Delay Emulation for supported values.

  2. -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           ∞          ∞
    
却一份温柔 2024-12-06 08:20:29

由于 iPhone 开发者选项适用于 wifi 网络共享,因此您可以获得具有 iOS 6 及更高版本的 iPhone(并且已设置为用于开发使用 xcode),将其设置为模拟所需的网络配置文件,将您的 Android 设备连接到其热点

Since iPhones developer option apply on wifi tethering, you can get an iPhone which has iOS 6 and above (and has been set to use for developments with the xcode), set it to emulate the desired network profile, connect your Android device to its hotspot

enter image description here

何其悲哀 2024-12-06 08:20:29

Android Studio v 1.5 或更高版本的更新
正如 @LouMorda 在下面的评论中提到的,原始帖子中提到的 Emulator 选项卡已在 Android Studio v 1.5 中删除。

现在,他们已将这些设置放置在 AVD Manager 的模拟器设置中。
要访问这些设置:

  1. 选择工具 ->安卓-> AVD Manager
  2. 单击编辑 AVD 按钮(铅笔图标)
  3. 显示高级设置按钮后可以访问网络设置

单击此处的 是它的显示方式的屏幕截图:
网络速度和Android Studio v 1.5 中的延迟设置

原始帖子
对于使用 Android Studio IDE 的任何人:

  1. 转到 Run ->编辑配置
  2. 选择Android Application -> [您的应用]
  3. 选择模拟器选项卡,
  4. 您可以在此处更改网络速度(互联网速度)和网络延迟(延迟)的不同值)来模拟不同的速度和延迟等或者

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

下面的屏幕截图描述了此运行配置屏幕的外观:

Android Studio beta 0.8 中的运行配置屏幕。 6

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

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

Update for Android Studio v 1.5 or greater
As @LouMorda mentioned in a comment below that the Emulator tab mentioned in original post has been removed in Android Studio v 1.5.

Now They've placed these settings in Simulator Settings in AVD Manager.
To access these settings:

  1. Select Tools -> Android -> AVD Manager
  2. Click the Edit AVD button (pencil icon)
  3. The Network Settings can be accessed after clicking the Show Advanced Settings button

Here is a screenshot of how it may appear:
Network Speed and Latency Settings in Android Studio v 1.5

Original Post
For anyone using Android Studio IDE:

  1. Go to Run -> Edit Configurations
  2. Select Android Application -> [Your App]
  3. Select Emulator tab
  4. Here you can change different values for Network Speed(internet speed) and Network Latency (delay) to simulate different speeds and latencies etc

Alternatively, you can enter various arguments in Additional command line options text field as mentioned in @inazaruk's answer.

The screenshot below describes how this Run Configuration screen looks like:

Run Configurations Screen in Android Studio beta 0.8.6

I know its a bit late to answer to this question, but i hope this helps others facing similar issues!

Edit
For anyone using eclipse, see @Abhi's answer below.

内心激荡 2024-12-06 08:20:29

我知道这是一个老问题但是...

现在有些手机设置为仅使用 2G。它非常适合在真实设备上模拟慢速互联网。

在此处输入图像描述

I know it's an old question but...

Some phones nowadays have a setting to utilize 2G only. It's perfect for simulating slow internet on a real device.

enter image description here

听,心雨的声音 2024-12-06 08:20:29

虽然已经很多年了,但是嘿,我会用我的 Genymotion 万无一失的方法来补充一下。

  • 下载 Charles 免费试用版:http://www.charlesproxy.com/download/

  • 安装

  • 点击代理->节流设置

  • 设置您的 HTTP 限制速度

  • 关闭该窗口

  • 单击代理 -> Throttling启用节流

  • 打开 Genymotion 模拟器

  • 打开 wifi 设置

  • 长按已启用的 wifi 连接

  • 单击修改网络

  • 单击显示高级选项

  • 代理设置为手动

  • 代理主机名设置为10.0.3.2

  • < p>将端口设置为8888

  • 单击保存

现在您的网络将受到限制!

Years old but hey, I'll chime in with my foolproof method with Genymotion.

  • Download the Charles free trial: http://www.charlesproxy.com/download/

  • Install it

  • ClickProxy -> Throttle Settings

  • Set up your HTTP throttled speeds

  • Close that window

  • Click Proxy -> Throttling to enable the throttle

  • Open up a Genymotion emulator

  • Open the wifi settings

  • Long press the enabled wifi connection

  • Click Modify Network

  • Click Show Advanced Options

  • Set Proxy to Manual

  • Set the Proxy hostname to 10.0.3.2

  • Set the Port to 8888

  • Click Save

And now your network will be throttled!

疏忽 2024-12-06 08:20:29

我有一个策略来解决你的问题。您可以使用代理应用程序来修改或监控您的网络状态。例如,查尔斯

您应该更改 Charles 的默认配置,如下图所示。

打开油门设置

最后,您会发现网络状态已被调整为较低的速度。

之前

“设置之后”

I have one strategy to settle your problem. You can use the application of proxy to modify or monitor your net status. e.g, Charles.

You ought to change the default config of the Charles like the following picture I posted.

Open Your Throttle Setting

Setting Your Throttle Setting

And finally, you will discover the net status has been shaped into lower pace.

Before

Setting After

甜宝宝 2024-12-06 08:20:29

您还可以在真实的 Android 设备上测试慢速互联网连接:

使用 Samsung Galaxy S8 + Android 8.0.0 进行测试

转到设置 -> 连接 -> 移动网络 ->在网络模式下,您可以选择仅使用2G3G连接

You are also able to test slow internet connectivity on an real android device:

Tested with Samsung Galaxy S8 + Android 8.0.0

Go to Settings -> Connection -> Mobile Network -> and under networkmode you can choose to only use 2G or 3G connections

小巷里的女流氓 2024-12-06 08:20:29

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

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

2- 转到蜂窝网络

3- 设置网络类型

Screenshot

In Android Studio, while running an emulator:

1- Hit settings button at the bottom of the emulator sidebar

2- Go to Cellular

3- Set Network Type

Screenshot

习惯成性 2024-12-06 08:20:29

有一种在真实设备上测试低速的简单方法,但似乎被忽视了。它确实需要 Mac 和以太网(或其他有线)网络连接。

在Mac上打开Wifi共享,将您的计算机变成Wifi热点,将您的设备连接到此。使用 Netlimiter/Charles Proxy 或 Network Link Conditioner(您可能已经安装)来控制速度。

有关更多详细信息并了解您应该测试哪种速度,请查看:http://opensignal.com/blog/2016/02/05/go-slow-how-why-to-test-apps-on-poor-connections/

There's a simple way of testing low speeds on a real device that seems to have been overlooked. It does require a Mac and an ethernet (or other wired) network connection.

Turn on Wifi sharing on the Mac, turning your computer into a Wifi hotspot, connect your device to this. Use Netlimiter/Charles Proxy or Network Link Conditioner (which you may have already installed) to control the speeds.

For more details and to understand what sort of speeds you should test on check out: http://opensignal.com/blog/2016/02/05/go-slow-how-why-to-test-apps-on-poor-connections/

南街九尾狐 2024-12-06 08:20:29

我很惊讶没有人提到这一点。您可以通过蓝牙进行连接,并将它们分开十多米(或有障碍物时更短)。您的连接真正很差。没有微波炉,没有电梯,不需要软件。

I'm surprised nobody mentioned this. You can tether via Bluetooth, and separate them by ten+ meters(or less with obstacles). You've got a real bad connection. No microwave, no elevator, no software needed.

—━☆沉默づ 2024-12-06 08:20:29

在模拟器中使用低/差连接测试应用程序的简单方法:

转到运行> 运行配置,选择您的Android应用程序,然后转到目标选项卡。
查看模拟器启动参数。在这里,您可以轻松修改网络速度和网络延迟。

Easy way to test your application with low/bad connection in emulator:

Go Run > Run configurations, select your Android Application, and there go to Target tab.
Look Emulator launch parameters. Here, you can easy modify Network Speed and Network Latency.

不寐倦长更 2024-12-06 08:20:29

Facebook 构建了一种名为增强流量控制的东西。他们的 GitHub 页面的简短摘要:

增强流量控制(ATC)是一种模拟网络状况的工具。它允许控制设备与互联网的连接。开发人员可以使用 ATC 在不同的网络条件下测试他们的应用程序,轻松模拟高速、移动甚至严重受损的网络。可以控制的连接方面包括:

  • 带宽
  • 延迟
  • 数据包丢失
  • 数据包损坏
  • 数据包订购

为了能够调整网络流量,ATC 必须在路由流量的设备上运行并查看设备的真实 IP 地址,例如您的网络网关。这还允许任何通过 ATC 路由的设备能够调整其流量。可以使用 Web 界面调整/取消流量调整,从而允许任何具有 Web 浏览器的设备使用 ATC,而无需客户端应用程序。

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

他们还写了一篇关于它的博客文章:https://code.facebook.com/posts/1561127100804165/augmented-traffic-control-a-tool-to-simulate-network-conditions/

Facebook built something called Augmented Traffic Control. A brief summary from their GitHub page:

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.

You can find it here on GitHub: https://github.com/facebook/augmented-traffic-control

They have also written a blog post about it: https://code.facebook.com/posts/1561127100804165/augmented-traffic-control-a-tool-to-simulate-network-conditions/

月竹挽风 2024-12-06 08:20:29

或者在实际设备上,您可以转到“设置”->“移动网络 ->首选网络类型并选择最慢的可用网络类型...
当然,这是非常有限的,但对于某些测试目的来说可能就足够了。

Or on an actual device you can go to Settings -> Mobile Networks -> Preferred network types and chose the slowest available...
Of course this is very limited, but for some test- purposes it might be enough.

嗫嚅 2024-12-06 08:20:29

Android studio AVD 更新:

  1. 打开 AVD 管理器
  2. 创建/编辑 AVD
  3. 单击高级设置
  4. 选择您首选的连接设置

没有微波炉或电梯:)

UPDATE on the Android studio AVD:

  1. open AVD manager
  2. create/edit AVD
  3. click advanced settings
  4. select your preferred connectivity setting

No microwaves or elevators :)

就像说晚安 2024-12-06 08:20:29

对于 Mac OS 用户,您可以使用 Network Link Conditioner,它可以从 Apple 下载。在mac上将其设置为AP,任何设备都可以连接它。

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

for and mac OS user you can use Network Link Conditioner which could be downloaded from apple. set it as a AP on mac and any divices could connected it.

you can either use facebook open source tools ATC
http://facebook.github.io/augmented-traffic-control/

ˇ宁静的妩媚 2024-12-06 08:20:29

我在这个问题上苦苦挣扎了半天,最后我找到了这个解决方案:

  • 在真实设备上进行测试总体来说没有多大意义,因为你必须经历很多事情才能使其工作。实现实际测试的唯一合理方法是让您的手机连接到低质量的蜂窝网络,例如 EDGE(如果您的电话公司提供的话)。您可以尝试通过在手机应用程序中拨打 *#*#4636#*#*

    来执行此操作。

  • 原始 Android 模拟器对于测试来说太慢,并且无法实现比解决方案更多的功能

最好的方法是使用 Genymotion。它是一个 Android 模拟器,性能比原来的 AVD 好得多,而且个人使用的版本是免费的。

Genymotion 模拟器

在 Genymotion 中创建虚拟设备后,只需执行 本教程为设备设置代理。

在主机上运行模拟不良网络条件的代理服务器,例如 CrapifyToxiproxy (我只测试了前者),你就可以开始了。

更新:

我刚刚意识到您也可以在真实设备上选择相同的策略。我觉得自己像个白痴,没有早点意识到这一点。只需在计算机上启动 Crapify 代理,将手机代理设置为计算机的本地地址,瞧,手机上的互联网就很糟糕。

I was struggling with this problem for half a day, finally I came to this solution:

  • Testing on a real device doesn't make much sense overall as you have to go through a lot to make it work. The only logical way to achieve real testing is to make your phone connect to a low quality cellular network, like EDGE, if your phone company provides it. You can try to do this by dialing *#*#4636#*#* in the phone app

  • The original Android emulator is way too slow for testing and doesn't achieve more than the solution above.

The best way to do this is using Genymotion. It's an Android emulator with much better performance than the original AVDs and the version for personal use is free.

Genymotion emulator

After you created your virtual device in Genymotion, just go through this tutorial to set a proxy for the device.

Run a proxy server on your host machine that simulates bad network conditions, like Crapify or Toxiproxy (I only tested the former) and you're good to go.

Update:

I just realized you can pick the very same strategy with real devices too. I feel like an idiot for not realizing it sooner. Just start a Crapify proxy on your computer, set your phone proxy to your computer's local address and voila, you've got crappy internet on your phone.

丢了幸福的猪 2024-12-06 08:20:29

跑吧>运行配置,选择您的 Android 应用程序,然后转到“目标”选项卡。如图所示进行更改。

在此处输入图像描述

Go Run > Run configurations, select your Android Application, and there go to Target tab. Do changes as shown in the figure.

enter image description here

栀子花开つ 2024-12-06 08:20:29

很旧的帖子,但我会加上我的两分钱。我对这款硬件产品非常满意(https://apposite-tech.com/products /linktropy-mini/ )这使我们能够模拟许多现实世界的条件。很长一段时间以来,我们都面临着对在模拟器或飞行模式下工作的各种问题进行故障排除的挑战。

我们有几种不同的配置文件设置,从零连接到边缘连接的各个阶段,具有不同程度的延迟、数据包丢失和误码。它的伟大之处在于我们可以即时更改这些内容,而无需在模拟器中重新启动应用程序。对于我们店来说这个价格是完全值得的,而且使用起来非常简单。

Very old post but I'll add my two cents. I have been VERY happy with this hardware product ( https://apposite-tech.com/products/linktropy-mini/ ) which has enabled us to simulate a lot of real-world conditions. For a long time we had challenges troubleshooting various things that would work in emulator or with airplane mode.

We have several different profiles setup from zero-connectivity to various stages of marginal connectivity, with different degrees of latency, packet loss, and bit-errors. The great thing about it is we can change these on the fly without having to relaunch the app in an emulator. The price has been entirely worth it for our shop, and it's dead simple to use.

酒废 2024-12-06 08:20:29

我需要限制 AndroidTV 本机设备上的低互联网连接,根据我所读到的内容,最合适的解决方案是直接在我的路由器中限制互联网访问。
进入路由器设置(本地是 192.168.0.1)->设置 DHCP 服务器(如果未运行)->选择设备的IP地址并设置限制;

I needed to throttle low internet on AndroidTV native device and based on what I have read, the most suitable solution was to limit the internet access directly in my router.
Go to router settings (locally it is smth like 192.168.0.1) -> set up DHCP server (if it's not running) -> choose IP address of a device and set the restriction;

鸩远一方 2024-12-06 08:20:29

正如@VicVu Charles(或任何其他代理工具)所建议的那样,这是一种更简单的方法。但我想补充一点,您也可以使用您的设备来执行此操作,而不仅仅是 genymotion 或其他模拟器。过程将是相同的:

修改设备/模拟器的 wifi 设置以使用手动代理。然后设置代理主机名&港口
一个。将主机名设置为系统的 ip(使用 ifconfig/ifconfig 获取 pc/mac 的 ip)
b.设置genymotion的端口号(检查charles中的代理设置)

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

as suggested by @VicVu Charles (or any other proxy tool) is an easier way to go. But I would Like to add that you can do this with your device also, not just genymotion or other emulators. Process will be the same:

Modify your device/emulator's wifi setting to use manual proxy. And then Set the Proxy hostname & port
a. set the hostname as ip of your system (get the ip of your pc/mac using ifconfig/ifconfig)
b. set the port number of genymotion (check the proxy settings in charles)

PS: Your device/emulator MUST be using the same wifi since the ip you are using will most probably be the private ip.

删除→记忆 2024-12-06 08:20:29
  1. 在Android Studio中打开终端并转到../../Android/sdk/tools。 “模拟器”可执行文件应在此处可用。

  2. 运行 ./emulator -netdelay "delay_in_millis" -avd "emulator_device_name"

    例如:./emulator -netdelay 60000 -avd Nexus_5_API_21

  3. 现在构建您的应用程序并将其安装在模拟器。

  4. 在应用程序中运行您的场景。

确保您在应用程序中更改了代码,为您的请求设置超时并处理该请求。

  1. Open terminal inAndroid Studio and Go to ../../Android/sdk/tools. 'emulator' executable should be available here.

  2. Run ./emulator -netdelay "delay_in_millis" -avd "emulator_device_name"

    Ex: ./emulator -netdelay 60000 -avd Nexus_5_API_21

  3. Now build your app and install it in emulator.

  4. Run your scenario in app.

Make sure you have your code changes in app that sets timeout to your request and handles that.

ㄟ。诗瑗 2024-12-06 08:20:29

只需从 Android studio 转到 Android 设备监视器,然后 DDMS ->模拟器控制。将有速度和延迟属性。

Just go to Android device monitor from Android studio , then DDMS -> Emulator Control.There will be Speed and Latency properties.

み零 2024-12-06 08:20:29

你试过这个吗?
设置-网络-更多-移动网络-网络模式-选择首选网络(例如2G)。

我使用的另一种方法是上面提到的。通过 iPhone 热点连接。
希望这有帮助。

have you tried this?
Settings - Networks - More - Mobile Networks - Network mode - Select preferred network (2G for example).

Another method i used was mentioned above. Connect via iPhone hot spot.
Hope this helps.

淡淡の花香 2024-12-06 08:20:29

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

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

例如 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

在我的应用程序中,我使用证书固定,因此您需要添加证书(私有+公共)

cat private.key public.key >证书.pem

你可以找到一个简单的教程 此处

您可以在此处找到其他脚本示例。

I'm using mitmproxy HTTPS proxy. https://mitmproxy.org/

Mitmproxy is an open source proxy application that allows intercepting HTTP and HTTPS connections between any HTTP(S) client. It allows to monitor, capture and alter these connections in realtime. Change request, response, header, ...
Additionally you can intercept different requests.

e.g. response_delay.py:

from mitmproxy import http
from time import sleep

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

Then executing this comment delays all responses from the server:

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

In my app I'm using certificate pinning, so you need to add the certificate (private + public)

cat private.key public.key > cert.pem

You can find a simple Tutorial here.

You can find other scripting examples here.

可爱咩 2024-12-06 08:20:29

我发现 netlimiter4 是限制模拟器数据的最佳解决方案。
它通过一个不错的图形用户界面提供精细控制,并为您提供有关每个进程的数据吞吐量的图形反馈。目前处于免费测试阶段。

输入图片此处描述

http://www.netlimiter.com/products/nl4

Play 商店上有一些应用程序可以对实际设备进行限制,但它们需要 root(我无法提供有关它们工作效果的任何建议,如果有的话 - YMMV.)

在 Play 商店中搜索 Bradybound,我无法发布多个链接..

I found netlimiter4 to be the best solution for throttling data to emulators.
It provides for granular control through a decent gui and gives you graphical feedback on the data throughput to each process. Currently in a free beta.

enter image description here

http://www.netlimiter.com/products/nl4

There are apps available on the play store to throttle to actual devices but they require root(I cant provide any advice as to how well they work, if at at all - YMMV.)

search for bradybound on the play store, I can't post more than one link..

ˇ宁静的妩媚 2024-12-06 08:20:29

您想测试没有网络连接还是只是慢速网络连接?如果是前者,您可以前往 Settings >无线与网络>飞行模式并打开飞行模式。这将让您在实际设备上测试网络不可用性。

Do you want to test for no network connection, or just a slow network connection? If the former, you can go to Settings > Wireless & networks > Airplane mode and turn Airplane mode on. That will let you test network unavailability on an actual device.

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