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

拜拜、爱过 提交于 2019-12-02 20:16:58
M D

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

Tx == Transmit Bytes Rx == Receive Bytes

There are three ways...

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

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

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

Madhukar Hebbar

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;
    }
}
Pratik Butani

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:

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!