0

Hi guys I am developing an app to display data rate on status bar like this.enter image description here

My code is :

private class DataStatUtil implements Runnable {

        private long startRX = 0;
        private long lastRx = 0;
        private Handler mHandler;
        private Context context;
        private Intent actionIntent;


        public DataStatUtil(Context context ,Handler handler) {
            this.context = context;
            mHandler = handler;
            startRX = TrafficStats.getTotalRxBytes();
        }

        @Override
        public void run() {

            long rxBytes = (TrafficStats.getTotalRxBytes()- startRX)/1024;
            startRX = TrafficStats.getTotalRxBytes();

            //my method to display on status bar
            notifyOnStatusBar(rxBytes);

            mHandler.postDelayed(this, 1000);

        }
    }

}

I am asking is this is the right way?

Alex K
  • 8,269
  • 9
  • 39
  • 57
Adarsh Gowda
  • 196
  • 2
  • 13

1 Answers1

0

You should find Transmitted bytes also to get the total bandwidth usage in your connection. A/C to the above given code, you are monitoring only the total receiving bytes.

check this link to get more information.

How do I programmatically show data usage of all applications?

Community
  • 1
  • 1
Arif A.
  • 933
  • 8
  • 14