Monday, April 7, 2014

android how to get the current app does not include wifi traffic


How to get the flow of the current app does not include wifi
Help solve, thank you!
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
TrafficStats.getUidRxBytes (int uid) can get to the same user id boot since the number of bytes received. If you do not share the same few apk user id. Then the value returned represents the number of bytes you this apk since boot accept.
TrafficStats.getMobileRxBytes () to get the number of bytes that can boot the phone since received over the mobile network.
SDK does not provide the number of bytes for each app to get through the mobile network api.
Reply:
I want to download android crazy notes, ah, ah, I rushed to my points to go! ! ! !
Reply:
I do not know how to do micro-channel.
Reply:
reference to the third floor u012126319 reply:
do not know how to do micro-channel.

Use a screwdriver to pry open the micro-channel look
Reply:
good! Check it out.
Reply:
I am now doing something similar abundance, the landlord solve it, please tell twelve
Reply:
I solved the first to get your application package name, and then based on the state of your network traffic statistics

public void method () {
ConnectivityManager connectMgr = (ConnectivityManager) this
. GetSystemService (Context.CONNECTIVITY_SERVICE);
ApplicationInfo info = getApplicationInfo ();
NetworkInfo netinfo = connectMgr.getActiveNetworkInfo ();
if (! netinfo = null | | netinfo.isAvailable ()) {
System.out.println ("========================");
if (netinfo.getType () == ConnectivityManager.TYPE_MOBILE) {
System.out.println (info.packageName);
String name = info.packageName;
if (name.equals ("com.example.demo")
| | Name == "com.example.demo") {
int uid = info.uid;
System.out.println (uid + ".............");
System.out.println ("2G/3G traffic consumed" + TrafficStats.getUidRxBytes (uid) + TrafficStats.getUidTxBytes (uid));
}
}
if (netinfo.getType () == ConnectivityManager.TYPE_WIFI) {
System.out.println (info.packageName);
String name = info.packageName;
if (name.equals ("com.example.demo")
| | Name == "com.example.demo") {
int uid = info.uid;
System.out.println (uid + ".............");
System.out.println (TrafficStats.getUidRxBytes (uid));
System.out.println (TrafficStats.getUidTxBytes (uid));
System.out.println ("wifi traffic consumed =" + ((int) TrafficStats.getUidRxBytes (uid) + (int) TrafficStats.getUidTxBytes (uid)));
}
}
}

}

No comments:

Post a Comment