[android] Simulate low network connectivity for Android

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.

This question is related to android connectivity

The answer is


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.


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


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


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.


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.


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!


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/


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.


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


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.


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.


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.


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


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/


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.


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 :)


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


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.


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


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


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


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;


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.


  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.


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


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/