本文整理汇总了Java中android.net.TrafficStats.getMobileTxPackets方法的典型用法代码示例。如果您正苦于以下问题:Java TrafficStats.getMobileTxPackets方法的具体用法?Java TrafficStats.getMobileTxPackets怎么用?Java TrafficStats.getMobileTxPackets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.TrafficStats
的用法示例。
在下文中一共展示了TrafficStats.getMobileTxPackets方法的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: 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;
}
示例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();
}
}
示例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;
}
示例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;
}