本文整理匯總了Java中android.net.TrafficStats.getTotalTxPackets方法的典型用法代碼示例。如果您正苦於以下問題:Java TrafficStats.getTotalTxPackets方法的具體用法?Java TrafficStats.getTotalTxPackets怎麽用?Java TrafficStats.getTotalTxPackets使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.net.TrafficStats
的用法示例。
在下文中一共展示了TrafficStats.getTotalTxPackets方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fetchValues
import android.net.TrafficStats; //導入方法依賴的package包/類
private boolean fetchValues() {
stats[0] = TrafficStats.getMobileRxPackets();
if (stats[0] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetPacketsService.getMetricInfo - mobile rx not supported");
return false;
}
stats[1] = TrafficStats.getMobileTxPackets();
if (stats[1] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetPacketsService.getMetricInfo - mobile tx not supported");
return false;
}
stats[2] = TrafficStats.getTotalRxPackets();
if (stats[2] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetPacketsService.getMetricInfo - total rx not supported");
return false;
}
stats[3] = TrafficStats.getTotalTxPackets();
if (stats[3] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetPacketsService.getMetricInfo - total tx not supported");
return false;
}
return true;
}
示例2: start
import android.net.TrafficStats; //導入方法依賴的package包/類
public void start() {
Logger.d(TAG, "thread start");
if (!mRunning) {
mRunning = true;
mThread = new Thread(new Runnable() {
@Override
public void run() {
while (mRunning) {
final long mobileRX = TrafficStats.getMobileRxBytes();
final long mobileRXP = TrafficStats.getMobileRxPackets();
final long mobileTX = TrafficStats.getMobileTxBytes();
final long mobileTXP = TrafficStats.getMobileTxPackets();
final long totalRX = TrafficStats.getTotalRxBytes();
final long totalRXP = TrafficStats.getTotalRxPackets();
final long totalTX = TrafficStats.getTotalTxBytes();
final long totalTXP = TrafficStats.getTotalTxPackets();
final TrafficInfo trafficInfo = new TrafficInfo(getCurrentDayTimestamp(System.currentTimeMillis()));
trafficInfo.setMobileRx(mobileRX);
trafficInfo.setMobileRxp(mobileRXP);
trafficInfo.setMobileTx(mobileTX);
trafficInfo.setMobileTxp(mobileTXP);
trafficInfo.setTotalRx(totalRX);
trafficInfo.setTotalRxp(totalRXP);
trafficInfo.setTotalTx(totalTX);
trafficInfo.setTotalTxp(totalTXP);
if (FeatureManager.SupportDataStatistic) {
TrafficDataHelper.update(mContext.getContentResolver(), trafficInfo);
}
final Message msg = mHandler.obtainMessage(MESSAGE_TRAFFIC_CHANGED);
msg.obj = trafficInfo;
msg.sendToTarget();
if (mRunning) {
synchronized (CheckTrafficTask.this) {
try {
CheckTrafficTask.this.wait(mRefreshInterval);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
if (!mRunning) {
break;
}
}
}
}, "CheckTrafficTask");
mThread.start();
}
}
示例3: fetchValues
import android.net.TrafficStats; //導入方法依賴的package包/類
/**
* Fetch updated values for network usage metrics.
*
* @return 0 if all metrics supported, positive if any metrics not supported
*/
private int fetchValues() {
int unsupported = 0;
values[0] = TrafficStats.getMobileRxBytes();
if (values[0] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetBytesService.getMetricInfo - mobile rx not supported");
unsupported++;
}
values[1] = TrafficStats.getMobileTxBytes();
if (values[1] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetBytesService.getMetricInfo - mobile tx not supported");
unsupported++;
}
values[2] = TrafficStats.getTotalRxBytes();
if (values[2] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetBytesService.getMetricInfo - total rx not supported");
unsupported++;
}
values[3] = TrafficStats.getTotalTxBytes();
if (values[3] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetBytesService.getMetricInfo - total tx not supported");
unsupported++;
}
values[4] = TrafficStats.getMobileRxPackets();
if (values[4] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetPacketsService.getMetricInfo - mobile rx not supported");
unsupported++;
}
values[5] = TrafficStats.getMobileTxPackets();
if (values[5] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetPacketsService.getMetricInfo - mobile tx not supported");
unsupported++;
}
values[6] = TrafficStats.getTotalRxPackets();
if (values[6] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetPacketsService.getMetricInfo - total rx not supported");
unsupported++;
}
values[7] = TrafficStats.getTotalTxPackets();
if (values[7] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetPacketsService.getMetricInfo - total tx not supported");
unsupported++;
}
return unsupported;
}
示例4: initWifivariable
import android.net.TrafficStats; //導入方法依賴的package包/類
public void initWifivariable(){
lastTransmitPackets = TrafficStats.getTotalTxPackets();
lastReceivePackets = TrafficStats.getTotalRxPackets();
}
示例5: getCurrentContextInfo
import android.net.TrafficStats; //導入方法依賴的package包/類
/**
* called by the timer and return the current context info of device
*
* @return a hash map that contains all the context data
*/
@SuppressLint("NewApi")
private HashMap<String, String> getCurrentContextInfo() {
HashMap<String, String> currentContext = new HashMap<String, String>();;
long intervalPktSend = 0;
long intervalPktRecv = 0;
long intervalSend = 0;
long intervalRecv = 0;
long sendBytes = TrafficStats.getTotalTxBytes();
long recvBytes = TrafficStats.getTotalRxBytes();
long sendPkt = TrafficStats.getTotalTxPackets();
long recvPkt = TrafficStats.getTotalRxPackets();
if (prevSend != -1 && prevRecv != -1) {
intervalSend = sendBytes - prevSend;
intervalRecv = recvBytes - prevRecv;
}
if (prevPktSend != -1 && prevPktRecv != -1) {
intervalPktSend = sendPkt - prevPktSend;
intervalPktRecv = recvPkt - prevPktRecv;
}
// we only return the context info if (1) it's the first time it gets called (2) we have
// change in the amount of packet/byte sent/received.
if (prevSend == -1 || prevRecv == -1 || prevPktSend == -1 || prevPktRecv == -1
|| intervalSend != 0 || intervalRecv != 0 || intervalPktSend != 0 || intervalPktRecv != 0) {
currentContext.put("timestamp", (System.currentTimeMillis() * 1000) + "");
currentContext.put("rssi", phoneUtils.getCurrentRssi() + "");
currentContext.put("inc_total_bytes_send", intervalSend + "");
currentContext.put("inc_total_bytes_recv", intervalRecv + "");
currentContext.put("inc_total_pkt_send", intervalPktSend + "");
currentContext.put("inc_total_pkt_recv", intervalPktRecv + "");
currentContext.put("battery_level", phoneUtils.getCurrentBatteryLevel() + "");
}
prevSend = sendBytes;
prevRecv = recvBytes;
prevPktSend = sendPkt;
prevPktRecv = recvPkt;
return currentContext;
}