????????????????????
????public static double Flow(String PackageName) throws IOException?? InterruptedException
????{
????double Flow1=GetFlow(PackageName);
????Thread.sleep(1000);
????double Flow=GetFlow(PackageName)-Flow1;
????//System.out.println(GetFlow()-Flow1);
????return Flow ;
????}
???????????
???????????????????? ??????????????????????????飬???ò???????????????????????? ???????????????????????
??????????????
???????
?????????????????????Android ?????????????????ο???
????Android??TrafficStats??
?????????????/proc/net/dev?????????
????Android????????????????????TrafficStats??????????
????????????TrafficStats.getTotalRxBytes()??
????????????TrafficStats.getTotalTxBytes());
?????????WIFI?????GPRS??????TrafficStats.getMobileRxBytes());
?????????Wifi?????GPRS??????TrafficStats.getMobileTxBytes());
???????????????????TrafficStats.getUidRxBytes(Uid));
???????????????????TrafficStats.getUidTxBytes(Uid));
package cn.sunzn.trafficmanger;
import android.app.Activity;
import android.net.TrafficStats;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/** ????????? 2G/3G ???????????????? */
TrafficStats.getMobileRxBytes();
/** ????????? 2G/3G ?????????????? */
TrafficStats.getMobileRxPackets();
/** ????????? 2G/3G ????????????????? */
TrafficStats.getMobileTxBytes();
/** ????????? 2G/3G ??????????????? */
TrafficStats.getMobileTxPackets();
/** ????????????????緽?????????????????(???? wifi) */
TrafficStats.getTotalRxBytes();
/** ????????????????緽???????????????(???? wifi) */
TrafficStats.getTotalRxPackets();
/** ????????????????緽?????????????????(???? wifi) */
TrafficStats.getTotalTxBytes();
/** ????????????????緽???????????????(???? wifi) */
TrafficStats.getTotalTxPackets();
/** ????????? UID ??????????????????????緽?????????????????(???? wifi) */
TrafficStats.getUidRxBytes(uid);
/** ????????? UID ???????ó?????????????緽?????????????????(???? wifi) */
TrafficStats.getUidTxBytes(uid);
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main?? menu);
return true;
}
}