how to count 3g traffic in android mobile? -


What do I want to do so that 3G traffic and WiFi traffic can be counted gradually? Now I know how to do with WiFi below is the source code for WiFi. In this way I can count all the WiFi traffic for all Android phones of manufacturing. But I have not got such a way for 3G, do anyone know? Private string obtained getProp (string prop) {string output = ""; to obtain wifi interface; {Class & lt;? & Gt; Sp = Class.forName ("android.os.SystemProperites"); Get the method = sp.getMethod ("get", string.class); Output = (string) get.invoke (empty, prop); } Hold (exception e) {e.printStackTrace (); } Return output; } // To get traffic from the system file ... ... if (connectinTpe == connectivity manager. TYPE_WIFI) {string wifiInterface = getProp ("wifi.interface"); If (wifi interface == blank. "" .. equal (wifi interface) wifiInterface = "eth0"; RxFile = "/ sys / class / net /" + wifiInterface + "/ statistics / rx_bytes"; TxFile = "/ sys / class / net /" + wifiInterface + "/ statistics / tx_bytes"; } ... ...

starting with API Level 8 (Android 2.2) Is a class that offers you:

The class that provides network traffic statistics, these data transmitted and received byte and network packets have been transmitted and received, on all the interfaces , On the mobile interface and on per-uid basis.

On the older versions, you can see the Traffic Stats in the approach you specified (i.e. / sys / class / net /...//code> / Code> There is an excellent mapping between methods and file locations. And in which the author is used to read the values ​​of those files, you must firstly type " / sys / class / net / rmnet0 / statistics / rx_bytes " file ("received bytes" value ) And if it is unsuccessful then "

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -