For statistic network traffic per APP, what I'm using now is Android TrafficStats
That I can get result like following :
- Youtube 50.30 MBytes
- Facebook 21.39 MBytes
- Google Play 103.38 MBytes
- (and more...)
As I know, the "Android Trafficstats" just a native pointer to a c file. (maybe an .so ?)
But it mixed Wifi & 3g traffic, is there any way to only get non-WiFi traffic statistic ?
Evening all, I got some way to do that...
First I have to create a class which extends BroadcasrReceiver, like this:
Manifest definition:
Codes:
And a phone stats listener below...
Finally, here's my logic
As I know, network traffic will go through WiFi only, if both 3G & WiFi are available.
After a long struggle, I am able to find the Solution for getting data over any interface for each installed Application in android device.
As Android provides TrafficStats Apis but these APIs are providing compile Data statistics for each app uid since device boot and Even APIs are not supporting to get the data over any interface for a particular application. Even if we rely over TraffiucStates APIS ,we get a new data statistics for each Application.
So I thought to use the hidden APIs to use this..
Here I am mentioning the Steps to get the data statistics for each application over any Interface in Android...
Establish a "INetworkStatsSession" session
Create a Network Template according to interface which you want to measure..
GetActive SubscriberID:
Collect the network HIStory of respective application byt passing application UIDs...
Get the total Consumption data:
Try the following code and turn off your 'WIFI' and check with only '3G'
Create a new Android project in Eclipse. Remember to use the TrafficStats class you must target the API for Android 2.2 (Froyo) or higher.
In the /res/layout folder we will create a main.xml resource. For this project, we are just using a series of text views in a vertically stacked linear layout.
With our layout in place we can move on to the /src folder. Create Main.java by extending the Activity class. Let’s also go ahead and declare three private class variables.
Main.java
We will use the on create override to initialize our private variables, as well as schedule a callback on the UI thread. Make a note of the check for the enum TrafficStats.UNSUPPORTED. While my experience with the TrafficStats class has been without a hitch, the official Google documentation states that some devices may not support this type of reporting and when that is the case the call returns the aforementioned value. For that reason it’s a good idea to write your code defensively, as I’ve demonstrated here.
Last but not least we need to update our display and reschedule the runnable.
i found way to get only wifi traffic
now wifibyte string show wifi total byte its work for me i hope that work for you