Android How to calculate network packet / network data

Internet access is currently very expensive. The provider used the charges as hell. We do not use an unlimited plan for the Internet. That is why I would like to develop capabilities for calculating (managing) a network packet / data usage.

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

I know that the data provider provides these features. I want my network data packets on my Android device to be supported by my application. But how can I do this in my own code. Any help would be appreciated. Thanks in advance.

+7
source share
2 answers

Please check it.

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); 
+4
source

Use the TrafficStats class starting with APILevel 8. You get general usage for each radio access technology and for each application.

See http://developer.android.com/reference/android/net/TrafficStats.html These are all static methods, like calling TrafficStats.getMobileRxBytes ()

0
source

All Articles