當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。