How can I check my Android app's network consumption? [closed]
Asked Answered
B

4

33

I need to check my Android app's Internet consumption. In my app I have a numerous number of web service APIs being called.

I want to know how much my app consumes the Internet in kB/MB at a full go.

How can I check that? Is there any tool to check that?

Barbary answered 19/4, 2016 at 6:43 Comment(2)
How is such a simple question not a duplicate more than 7 years after Stack Overflow launched?Fogged
@PeterMortensen Actually i already mark as Duplicate but all the questions asked related to get Network Data Usage programatically but in this question OP asked how to get it by using some Tools?Holpen
H
26

Android Studio 2.0 Introduce new Network section in Android Monitor which can help you with your problem.

enter image description here

Tx == Transmit Bytes Rx == Receive Bytes
Holpen answered 19/4, 2016 at 6:48 Comment(1)
I know its an old question, but how to you get the total used megabytes for a period of time using this tool? The graph only indicates transmission rate at a specific point in time but not the total transmitted so far figure. I was hoping that i could just mark a section on the graph and get the sum but to no luck unfortunately.Incogitable
E
11

There are three ways...

  1. You can view in Device/Emulator. Go to Setting -> Data usage, and find your application in the list Enter image description here

  2. In Eclipse, select DDMS (perspective) -> Select your package from Devices (left side) -> Click on Network Statistics tab -> Click Start enter image description here

  3. As already answered, in Android Studio, go to Android Monitor (bottom tab) -> Network (tab) -> look for Tx (Transmit Data) / Rx (Receive Data) Enter image description here

Ecospecies answered 19/4, 2016 at 7:13 Comment(0)
M
8

For view purposes, you can check it in the monitor as mentioned by MD.

To store, you can do that programmatically

    int UID = android.os.Process.myUid();
    rxBytes += getUidRxBytes(UID);
    txBytes += getUidTxBytes(UID);
    /**
     * Read UID Rx Bytes
     *
     * @param uid
     * @return rxBytes
     */
    public Long getUidRxBytes(int uid) {
        BufferedReader reader;
        Long rxBytes = 0L;
        try {
            reader = new BufferedReader(new FileReader("/proc/uid_stat/" + uid
                    + "/tcp_rcv"));
            rxBytes = Long.parseLong(reader.readLine());
            reader.close();
        }
        catch (FileNotFoundException e) {
            rxBytes = TrafficStats.getUidRxBytes(uid);
            //e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        return rxBytes;
    }

    /**
     * Read UID Tx Bytes
     *
     * @param uid
     * @return txBytes
     */
    public Long getUidTxBytes(int uid) {
        BufferedReader reader;
        Long txBytes = 0L;
        try {
            reader = new BufferedReader(new FileReader("/proc/uid_stat/" + uid
                    + "/tcp_snd"));
            txBytes = Long.parseLong(reader.readLine());
            reader.close();
        }
        catch (FileNotFoundException e) {
            txBytes = TrafficStats.getUidTxBytes(uid);
            //e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        return txBytes;
    }
}
Maroney answered 19/4, 2016 at 7:0 Comment(2)
Nice sample, It is helped me lot.Prickett
Not working since Android 6Horselaugh
S
6

Have a look: Android Monitor.

In that there are many topics that you can monitor.

You will find Network Monitor.

Displaying a Running App in the Network Monitor:

Follow these steps:

  • Connect a hardware device.
  • Display Android Monitor.
  • Click the Network tab.
  • Open an app project and run it on the hardware device.
  • To start the Network Monitor, click Pause Pause icon to deselect it.

Any network traffic begins to appear in the Network Monitor:

Enter image description here

The Network Monitor adds up the amount of time it takes for the device to transmit and receive kilobytes of data. The y-axis is in kilobytes per second. The x-axis starts with seconds, and then minutes and seconds, and so on.

  • To stop the Network Monitor, click Pause Pause icon again to select it.

Reference: Android Monitor

Sierrasiesser answered 19/4, 2016 at 7:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.