Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android How to calculate network usage packet/data

Now a days Internet access is very costly.The provider used charges like hell. We do not use unlimited plan for internet.That's why I would like to develop an that can facilities to calculate(manage) network package/data usage.

Suppose I have activated 5GB data plan.So I need to check before surfing net,upload/download things.

I know some Data provider provides these facility .I want to capture network data packets on my android device by my app. But How can I do that into my own code. Any help will be appreciated. Thank you advance

like image 567
Maidul Avatar asked Sep 05 '12 13:09

Maidul


1 Answers

Please check that.

TextView infoView = (TextView)findViewById(R.id.traffic_info);
String info = "";

info += "Mobile Interface:\n";
info += ("\tReceived: " + TrafficStats.getMobileRxBytes() + " bytes / " + TrafficStats.getMobileRxPackets() + " packets\n");
info += ("\tTransmitted: " + TrafficStats.getMobileTxBytes() + " bytes / " + TrafficStats.getMobileTxPackets() + " packets\n");

info += "All Network Interface:\n";
info += ("\tReceived: " + TrafficStats.getTotalRxBytes() + " bytes / " + TrafficStats.getTotalRxPackets() + " packets\n");
info += ("\tTransmitted: " + TrafficStats.getTotalTxBytes() + " bytes / " + TrafficStats.getTotalTxPackets() + " packets\n");

infoView.setText(info);
like image 178
Maidul Avatar answered Oct 20 '22 19:10

Maidul