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


Java TrafficStats.getMobileRxPackets方法代码示例

本文整理汇总了Java中android.net.TrafficStats.getMobileRxPackets方法的典型用法代码示例。如果您正苦于以下问题:Java TrafficStats.getMobileRxPackets方法的具体用法?Java TrafficStats.getMobileRxPackets怎么用?Java TrafficStats.getMobileRxPackets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.net.TrafficStats的用法示例。


在下文中一共展示了TrafficStats.getMobileRxPackets方法的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: getPacketsSent

import android.net.TrafficStats; //导入方法依赖的package包/类
/**
 * Determine how many packets, so far, have been sent (the contents of /proc/net/dev/). This is
 * a global value. We use this to determine if any other app anywhere on the phone may have sent
 * interfering traffic that might have changed the RRC state without our knowledge.
 * 
 * @return Two values: number of bytes or packets received at index 0, followed by the number
 *         sent at index 1.
 */
public long[] getPacketsSent() {
  long[] retval = {-1, -1};
  if (bySize) {
    retval[0] = TrafficStats.getMobileRxBytes();
    retval[1] = TrafficStats.getMobileTxBytes();

  } else {
    retval[0] = TrafficStats.getMobileRxPackets();
    retval[1] = TrafficStats.getMobileTxPackets();
  }

  return retval;
}
 
开发者ID:laoyaosniper,项目名称:Mobilyzer,代码行数:22,代码来源:RRCTask.java

示例3: 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

示例4: 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

示例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
 */
private HashMap<String, String> getCurrentContextInfo() {
  HashMap<String, String> currentContext = new HashMap<String, String>();;
  long prevSend = 0;
  long prevRecv = 0;
  long sendBytes = 0;
  long recvBytes = 0;
  long intervalSend = 0;
  long intervalRecv = 0;
  long prevPktSend = 0;
  long prevPktRecv = 0;
  long sendPkt = 0;
  long recvPkt = 0;
  long intervalPktSend = 0;
  long intervalPktRecv = 0;

  sendBytes = TrafficStats.getMobileTxBytes();
  recvBytes = TrafficStats.getMobileRxBytes();
  sendPkt = TrafficStats.getMobileTxPackets();
  sendPkt = TrafficStats.getMobileRxPackets();
  if (prevSend > 0 || prevRecv > 0) {
    intervalSend = sendBytes - prevSend;
    intervalRecv = recvBytes - prevRecv;
  }
  if (prevPktSend > 0 || prevPktRecv > 0) {
    intervalPktSend = sendPkt - prevPktSend;
    intervalPktRecv = recvPkt - prevPktRecv;
  }
  prevSend = sendBytes;
  prevRecv = recvBytes;
  prevPktSend = sendPkt;
  prevPktRecv = recvPkt;

  currentContext.put("timestamp", (System.currentTimeMillis() * 1000) + "");
  currentContext.put("rssi", phoneUtils.getCurrentRssi() + "");
  currentContext.put("inc_mobile_bytes_send", intervalSend + "");
  currentContext.put("inc_mobile_bytes_recv", intervalRecv + "");
  currentContext.put("inc_mobile_pkt_send", intervalPktSend + "");
  currentContext.put("inc_mobile_pkt_recv", intervalPktRecv + "");
  currentContext.put("battery_level", phoneUtils.getCurrentBatteryLevel() + "");
  return currentContext;
}
 
开发者ID:laoyaosniper,项目名称:Mobiperf-Library,代码行数:47,代码来源:ContextCollector.java


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