当前位置: 首页>>代码示例>>Java>>正文


Java TrafficStats.getTotalTxPackets方法代码示例

本文整理汇总了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;
}
 
开发者ID:Sean1988,项目名称:CIMON_Android,代码行数:24,代码来源:NetPacketsService.java

示例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();
    }
}
 
开发者ID:xujunbin,项目名称:FloatWindow,代码行数:56,代码来源:DeamonService.java

示例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;
}
 
开发者ID:Sean1988,项目名称:CIMON_Android,代码行数:50,代码来源:NetBytesService.java

示例4: initWifivariable

import android.net.TrafficStats; //导入方法依赖的package包/类
public void initWifivariable(){
	lastTransmitPackets = TrafficStats.getTotalTxPackets();
	lastReceivePackets = TrafficStats.getTotalRxPackets();
}
 
开发者ID:PowerLab,项目名称:PowerDoctor,代码行数:5,代码来源:OSMonitorService.java

示例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;
}
 
开发者ID:laoyaosniper,项目名称:Mobilyzer,代码行数:50,代码来源:ContextCollector.java


注:本文中的android.net.TrafficStats.getTotalTxPackets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。