1

My English is not good!. I had a problem, I'm trying to get mobile data usage and using TrafficStats of android. I have downloaded the downloaded, uploaded data using:

public long d = 0;
public long u = 0
private void getSpeed() {
    totalDownload += ((((TrafficStats.getMobileRxBytes() - d) / 1024) / 1024));
    totalUpload += ((((TrafficStats.getMobileTxBytes() - u) / 1024) / 1024));

    total += totalDownload + totalUpload;

    tvDownload.setText( totalDownload + "Mb" );
    tvUpload.setText( totalUpload + " Mb" );
    tvTotal.setText( total + "Mb" );
    Log.d( "getSpeed", "totalData: " + totalDownload );

    d = TrafficStats.getMobileRxBytes();
    u = TrafficStats.getMobileTxBytes();

}

Everything Ok, but when I turn on Wifi, the method returns 0/0. How to get mobile data usage when using wifi?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

0 Answers0