Simulate low network connectivity for Android [closed]
Asked Answered
F

27

292

I would like to test my application for cases of low network connectivity. Except standing in the elevator, what is the best way to do this? I've tried wrapping my phone in an aluminum foil, but it didn't help much.

I need to test it on a real device, not in an emulator.

Felid answered 11/8, 2011 at 12:57 Comment(2)
Also research Faraday cages. They are easy to build.Drawback
unfortunately this thread is closed. but I found a useful app on the Play Store called Throttly (it is not mine) . I think it is perfect to simulate slow connectionRemediosremedy
N
153

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           ∞          ∞
    
Nancynandor answered 11/8, 2011 at 13:3 Comment(11)
thanks a lot, but as I said, I would like to test on a real device. any way I can do this on a htc or samsung phone?Felid
No you can't. Unless, you do a real field testing :)Amalita
My guess is that the only way to go, is to have a wi-fi router/AP which can control network speed. This is more of an network admin things. But this should theoretically be possible.Nancynandor
I've used the elevator :) but thanx everyoneFelid
For simulating latency over HTTP, use ResponseCache.setDefault(new CacheResponse(){...}) and put a Thread.sleep(200) call in there. This has the advantage of being programatically controlled (i.e. only just in one activity) and not affecting other processes. However, for a more realistic test, you should set the limit on your router or using the tc command (from busybox).Echinoid
Why was this accepted as the answer? The question clearly stated "not in an emulator"Weise
Thats also possible to set in a "nice" menu: https://mcmap.net/q/102140/-how-to-limit-speed-of-internet-connection-on-android-emulatorBlarney
You also can use "network speed <speed>" and "network delay <delay>" directly in emulator consoleCervin
To get to the emulator console, first: telnet localhost 5554 then you can run network speed <speed>Gelatin
Since I've noticed all of the solutions here are workaround, I decided to request it on the issue-tracker: issuetracker.google.com/issues/122785998 . Please consider starring it.Mesothorax
I don't want to use emulator! I have to use a physical device! How to do that???Neddie
B
322

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...

Babettebabeuf answered 25/12, 2011 at 16:16 Comment(7)
Wow, now if you could suggest me a way to fit myself into the oven too. And ovens are designed for shielding 2.4 GHz. It may not work for lower frequencies. IDK!Ahriman
did not work in my microwave (i.e. connection was still decent)! Agh :|Albuquerque
If you have a USB cord attached, the signal can sneak in that way. If it is inside the microwave with no cord at all attached, it should not get a signal. You should be able to achieve this effect also with aluminum foil, which won't melt the phone because you can't accidentally turn the phone off.Girlfriend
The microwave oven is still a good option if you need to trigger an immediate disconnection and don't require further user interaction, which was my particular use-case.Disquieting
Thank God chrome has implemented something to help us to achieve thatSubtotal
What about Android emulator? Is there a microwave oven emulator?Coalition
Thank me later! Working with your device under a fluorescent light using Wi-Fi will significantly impact the speed.Huck
N
153

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           ∞          ∞
    
Nancynandor answered 11/8, 2011 at 13:3 Comment(11)
thanks a lot, but as I said, I would like to test on a real device. any way I can do this on a htc or samsung phone?Felid
No you can't. Unless, you do a real field testing :)Amalita
My guess is that the only way to go, is to have a wi-fi router/AP which can control network speed. This is more of an network admin things. But this should theoretically be possible.Nancynandor
I've used the elevator :) but thanx everyoneFelid
For simulating latency over HTTP, use ResponseCache.setDefault(new CacheResponse(){...}) and put a Thread.sleep(200) call in there. This has the advantage of being programatically controlled (i.e. only just in one activity) and not affecting other processes. However, for a more realistic test, you should set the limit on your router or using the tc command (from busybox).Echinoid
Why was this accepted as the answer? The question clearly stated "not in an emulator"Weise
Thats also possible to set in a "nice" menu: https://mcmap.net/q/102140/-how-to-limit-speed-of-internet-connection-on-android-emulatorBlarney
You also can use "network speed <speed>" and "network delay <delay>" directly in emulator consoleCervin
To get to the emulator console, first: telnet localhost 5554 then you can run network speed <speed>Gelatin
Since I've noticed all of the solutions here are workaround, I decided to request it on the issue-tracker: issuetracker.google.com/issues/122785998 . Please consider starring it.Mesothorax
I don't want to use emulator! I have to use a physical device! How to do that???Neddie
L
119

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

Lymphocytosis answered 5/6, 2013 at 13:0 Comment(8)
This was the solution we arrived at too. It's a shame that this is the most sane option available. It should be noted in the answer that the iPhone requires a 3G/cellular connection for tethering to work. Also should note the upload/download speeds need in the iPhone utility need to be inverted to be in respect to the tethered device.Weise
Brilliant! Silly that this is the best option, especially since the emulator can do it.Willful
The iPhone emulator can tether WiFi?Lymphocytosis
Thanks. Was confused how to set it up. This is how - if you are on a cellular plan that permits Personal Hotspots. I am using iOS 7.12 1) go to SETTINGS->Cellular->Personal Hotspot 2) slide Personal Hotspot switch to right so it is green/on (can change password if you prefer) 3) go back, back and scroll down to Developer 4) scroll down to Network Link Conditioner and tap it. slide ENABLE to right so that it is green/on finally choose a profile. I chose "Very Bad Network". This gave me ping (2198ms) download (0.05Mbps) upload (0.08Mbps) 5) Connect your Android to hotspot!Bags
Nice thought, I didn't think of this option thought I have many iDevices aroundLegionary
Brilliant. ThanksMentality
I cannot stop laughing but this is the best solution in the whole lot to simulate slow network on a real device. ThanksObjectivity
This answer gave me an idea that I can also use Mac "Network Link Conditioner" and hotspot to do the same thing.Adair
C
94

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.

Claman answered 1/9, 2014 at 11:8 Comment(3)
This tab has been removed in Android Studio v1.5Highbinder
@S1LENT WARRIOR What is latency and what is the difference between (for example) "speed:edge, latency:none" and "speed:full, latency:edge"?Horologist
@JohnnyFive speed refers to your network speed, and latency means the network delay.Claman
A
60

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

Audry answered 19/3, 2015 at 8:42 Comment(4)
perfect ! back to edge and an upload at 9kbyte/s .Turnage
Great, this perfectly suits my current need. In my room, a 200KB upload almost always fails on 2G :)Svetlanasvoboda
This guy is the real MVP.Penhall
There is a small but critical difference here. When you downgrade your phone's network from 3g to 2g, you still have a stable 2g connection. In real world, 2g connections wont be stabe and it will have packet loss. To simulate 2g with packet loss, you can use the solution suggested by @Kirill Kulakov since IOS alows you to configure the percentage of packet loss. Just a FYI for future readers :)Haddington
U
36

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!

Untie answered 4/5, 2015 at 23:12 Comment(2)
where did you get the 10.0.3.2 hostname from? is that charle's default?Otis
hostname should be the computer running Charles local network addressFrustum
B
18

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

Buttonwood answered 15/1, 2018 at 7:11 Comment(1)
This is the only adequate solution so far :DNebulose
B
18

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

Boatel answered 11/10, 2018 at 8:6 Comment(0)
O
15

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

Obscenity answered 24/9, 2018 at 9:19 Comment(0)
T
10

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/

Tragic answered 6/2, 2016 at 17:44 Comment(2)
Using the "Sharing" preference pane, you can share most any connection to most any other. I set it to share my WiFi connection over Bluetooth. (The connect via bluetooth options did not appear on my Android phone until this was set up.)Kicksorter
To install the Network Link Conditioner Tool: https://mcmap.net/q/102141/-installing-apple-39-s-network-link-conditioner-toolThundershower
S
10

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.

Sigmund answered 31/5, 2018 at 16:14 Comment(1)
This is actually a good solution, unless you have a very good Bluetooth connection. Need to use an old device for this. :)Mesothorax
G
9

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.

Gamez answered 8/8, 2013 at 13:27 Comment(0)
S
7

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/

Sunwise answered 8/11, 2016 at 13:41 Comment(0)
L
6

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.

Lois answered 25/9, 2014 at 10:32 Comment(0)
C
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 :)

Cyperaceous answered 18/6, 2015 at 8:13 Comment(0)
E
3

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/

Electromotor answered 22/9, 2015 at 8:34 Comment(0)
F
3

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.

Flutterboard answered 23/8, 2016 at 6:17 Comment(0)
I
2

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

Istle answered 27/2, 2015 at 9:16 Comment(0)
S
2

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.

Schipperke answered 2/4, 2019 at 15:35 Comment(0)
C
2

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;

Cycle answered 16/3, 2020 at 14:9 Comment(0)
F
1

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.

Finedrawn answered 3/7, 2015 at 7:26 Comment(0)
C
1
  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.

Choreodrama answered 25/11, 2015 at 9:50 Comment(0)
B
1

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

Basophil answered 3/12, 2015 at 11:15 Comment(0)
R
1

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. screenshot

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..

Reims answered 15/12, 2015 at 18:41 Comment(0)
C
1

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.

Cartier answered 27/3, 2018 at 10:57 Comment(0)
L
1

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.

Lindblad answered 27/6, 2018 at 15:6 Comment(0)
L
-1

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.

Liddie answered 23/9, 2011 at 15:45 Comment(2)
Thanks, but I was trying to test for low network connectivity. Eg. for a low EDGE signal or something like that.Felid
Ah. Too bad you can't turn off 3G and drop back to EDGE roaming. At least, on my phone you can't.Liddie

© 2022 - 2024 — McMap. All rights reserved.