android.net.TrafficStats#getMobileTxBytes ( )源码实例Demo

下面列出了android.net.TrafficStats#getMobileTxBytes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MobileGuard   文件: TrafficStatsActivity.java
/**
 * init data
 */
@Override
protected void initData() {
    long totalRxBytes = TrafficStats.getTotalRxBytes();
    long totalTxBytes = TrafficStats.getTotalTxBytes();
    long mobileRxBytes = TrafficStats.getMobileRxBytes();
    long mobileTxBytes = TrafficStats.getMobileTxBytes();

    long totalBytes = totalRxBytes + totalTxBytes;
    long mobileBytes = mobileRxBytes + mobileTxBytes;

    tvTotalTrafficStatsSum.setText(getString(R.string.total_traffic_stats_sum, Formatter.formatFileSize(this, totalBytes)));
    tvMobileTrafficStatsSum.setText(getString(R.string.mobile_traffic_stats_sum, Formatter.formatFileSize(this, mobileBytes)));
    tvTotalTrafficStats.setText(getString(R.string.traffic_stats_upload_download, Formatter.formatFileSize(this, totalTxBytes), Formatter.formatFileSize(this, totalRxBytes)));
    tvMobileTrafficStats.setText(getString(R.string.traffic_stats_upload_download, Formatter.formatFileSize(this, mobileTxBytes), Formatter.formatFileSize(this, mobileRxBytes)));

}
 
源代码2 项目: PracticeDemo   文件: DeviceInfoActivty.java
@Override
public boolean handleMessage(Message msg) {

    //不准?...

    long mrx = TrafficStats.getMobileRxBytes() / 1024; ////获取通过Mobile连接收到的字节总数,不包含WiFi
    long mtx = TrafficStats.getMobileTxBytes() / 1024; //Mobile发送的总字节数
    long trx = (long) ((TrafficStats.getTotalRxBytes() - mTotalRxBytes) * 1.00f / 1024);
    mTotalRxBytes = TrafficStats.getTotalRxBytes(); //获取总的接受字节数,包含Mobile和WiFi等
    long ttx = TrafficStats.getTotalTxBytes() / 1024; //总的发送字节数,包含Mobile和WiFi等
    long uidrx = TrafficStats.getUidRxBytes(getApplicationInfo().uid) / 1024;//获取某个网络UID的接受字节数,某一个进程的总接收量
    long uidtx = TrafficStats.getUidTxBytes(getApplicationInfo().uid) / 1024;//获取某个网络UID的发送字节数,某一个进程的总发送量
    StringBuilder sb = new StringBuilder();

    sb.append("mrx:" + mrx + "\n\r")
            .append("mtx:" + mtx + "\n\r")
            .append("trx:" + trx + "\n\r")
            .append("ttx:" + ttx + "\n\r")
            .append("uidrx:" + uidrx + "\n\r")
            .append("uidtx:" + uidtx + "\n\r")
    ;
    mTvDeviceInfo.setText(sb.toString());
    mHandler.sendEmptyMessageDelayed(0, 1000);

    return true;
}
 
源代码3 项目: GravityBox   文件: ModSmartRadio.java
private void scheduleAlarm() {
    Intent intent = new Intent(ACTION_CHANGE_MODE_ALARM);
    mPendingIntent = PendingIntent.getBroadcast(mContext, 1, intent, PendingIntent.FLAG_ONE_SHOT);
    long triggerAtMillis = System.currentTimeMillis() + mScreenOffDelay*60*1000;
    mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, triggerAtMillis, mPendingIntent);
    mLinkActivity.timestamp = System.currentTimeMillis();
    mLinkActivity.rxBytes = TrafficStats.getMobileRxBytes();
    mLinkActivity.txBytes = TrafficStats.getMobileTxBytes();
}
 
源代码4 项目: GravityBox   文件: ModSmartRadio.java
private boolean shouldPostponeAlarm() {
    boolean postpone = false;
    if (mAdaptiveDelayThreshold > 0) {
        // if there's link activity higher than defined threshold
        long rxDelta = TrafficStats.getMobileRxBytes() - mLinkActivity.rxBytes;
        long txDelta = TrafficStats.getMobileTxBytes() - mLinkActivity.txBytes;
        long timeDelta = System.currentTimeMillis() - mLinkActivity.timestamp;
        long speedRxKBs = (long)(rxDelta / (timeDelta / 1000f)) / 1024;
        long speedTxKBs = (long)(txDelta / (timeDelta / 1000f)) / 1024;
        postpone |= speedTxKBs >= mAdaptiveDelayThreshold || speedRxKBs >= mAdaptiveDelayThreshold;
        if (DEBUG) log("shouldPostponeAlarm: speedRxKBs=" + speedRxKBs +
                "; speedTxKBs=" + speedTxKBs + "; threshold=" + mAdaptiveDelayThreshold);
    }
    return postpone;
}
 
源代码5 项目: AndroidNetworkSpeed   文件: MyWindowManager.java
public void initData() {
    mobileRecvSum = TrafficStats.getMobileRxBytes();
    mobileSendSum = TrafficStats.getMobileTxBytes();
    wlanRecvSum = TrafficStats.getTotalRxBytes() - mobileRecvSum;
    wlanSendSum = TrafficStats.getTotalTxBytes() - mobileSendSum;
    rxtxTotal = TrafficStats.getTotalRxBytes()
            + TrafficStats.getTotalTxBytes();
}
 
源代码6 项目: trafficstats-example   文件: main.java
public void run() {
    long mobile = TrafficStats.getMobileRxBytes() + TrafficStats.getMobileTxBytes();
    long total = TrafficStats.getTotalRxBytes() + TrafficStats.getTotalTxBytes();
    tvDataUsageWiFi.setText("" + (total - mobile) / 1024 + " Kb");
    tvDataUsageMobile.setText("" + mobile / 1024 + " Kb");
    tvDataUsageTotal.setText("" + total / 1024 + " Kb");
    if (dataUsageTotalLast != total) {
        dataUsageTotalLast = total;
        updateAdapter();
    }
    handler.postDelayed(runnable, 5000);
}
 
源代码7 项目: Mobilyzer   文件: RRCTask.java
/**
 * 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;
}
 
源代码8 项目: callmeter   文件: Device.java
/**
 * {@inheritDoc}
 */
@Override
public long getCellTxBytes() throws IOException {
    final long l = TrafficStats.getMobileTxBytes();
    if (l < 0L) {
        return 0L;
    }
    return l;
}
 
源代码9 项目: callmeter   文件: Device.java
/**
 * {@inheritDoc}
 */
@Override
public long getWiFiTxBytes() throws IOException {
    final long l = TrafficStats.getMobileTxBytes();
    final long la = TrafficStats.getTotalTxBytes();
    if (la < 0L || la < l) {
        return 0L;
    }
    return la - l;
}
 
源代码10 项目: RxTools-master   文件: RxNetSpeedView.java
public void updateViewData() {

        long tempSum = TrafficStats.getTotalRxBytes()
                + TrafficStats.getTotalTxBytes();
        long rxtxLast = tempSum - rxtxTotal;
        double totalSpeed = rxtxLast * 1000 / TIME_SPAN;
        rxtxTotal = tempSum;
        long tempMobileRx = TrafficStats.getMobileRxBytes();
        long tempMobileTx = TrafficStats.getMobileTxBytes();
        long tempWlanRx = TrafficStats.getTotalRxBytes() - tempMobileRx;
        long tempWlanTx = TrafficStats.getTotalTxBytes() - tempMobileTx;
        long mobileLastRecv = tempMobileRx - mobileRecvSum;
        long mobileLastSend = tempMobileTx - mobileSendSum;
        long wlanLastRecv = tempWlanRx - wlanRecvSum;
        long wlanLastSend = tempWlanTx - wlanSendSum;
        double mobileRecvSpeed = mobileLastRecv * 1000 / TIME_SPAN;
        double mobileSendSpeed = mobileLastSend * 1000 / TIME_SPAN;
        double wlanRecvSpeed = wlanLastRecv * 1000 / TIME_SPAN;
        double wlanSendSpeed = wlanLastSend * 1000 / TIME_SPAN;
        mobileRecvSum = tempMobileRx;
        mobileSendSum = tempMobileTx;
        wlanRecvSum = tempWlanRx;
        wlanSendSum = tempWlanTx;
        //==========================================================
        if (isMulti) {
            if (mobileRecvSpeed >= 0d) {
                tvMobileRx.setText(showSpeed(mobileRecvSpeed));
            }
            if (mobileSendSpeed >= 0d) {
                tvMobileTx.setText(showSpeed(mobileSendSpeed));
            }
            if (wlanRecvSpeed >= 0d) {
                tvWlanRx.setText(showSpeed(wlanRecvSpeed));
            }
            if (wlanSendSpeed >= 0d) {
                tvWlanTx.setText(showSpeed(wlanSendSpeed));
            }
        } else {
            //==============================================================
            if (totalSpeed >= 0d) {
                tvSum.setText(showSpeed(totalSpeed));
            }
        }
        //==============================================================
    }
 
源代码11 项目: GTTools   文件: NETUtils.java
public static long getNetTxMobileBytes() {
	long total = TrafficStats.getMobileTxBytes();
	return total;
}
 
源代码12 项目: AndroidNetworkSpeed   文件: MyWindowManager.java
public void updateViewData(Context context) {

        long tempSum = TrafficStats.getTotalRxBytes()
                + TrafficStats.getTotalTxBytes();
        long rxtxLast = tempSum - rxtxTotal;
        double totalSpeed = rxtxLast * 1000 / TIME_SPAN;
        rxtxTotal = tempSum;
        long tempMobileRx = TrafficStats.getMobileRxBytes();
        long tempMobileTx = TrafficStats.getMobileTxBytes();
        long tempWlanRx = TrafficStats.getTotalRxBytes() - tempMobileRx;
        long tempWlanTx = TrafficStats.getTotalTxBytes() - tempMobileTx;
        long mobileLastRecv = tempMobileRx - mobileRecvSum;
        long mobileLastSend = tempMobileTx - mobileSendSum;
        long wlanLastRecv = tempWlanRx - wlanRecvSum;
        long wlanLastSend = tempWlanTx - wlanSendSum;
        double mobileRecvSpeed = mobileLastRecv * 1000 / TIME_SPAN;
        double mobileSendSpeed = mobileLastSend * 1000 / TIME_SPAN;
        double wlanRecvSpeed = wlanLastRecv * 1000 / TIME_SPAN;
        double wlanSendSpeed = wlanLastSend * 1000 / TIME_SPAN;
        mobileRecvSum = tempMobileRx;
        mobileSendSum = tempMobileTx;
        wlanRecvSum = tempWlanRx;
        wlanSendSum = tempWlanTx;
        if (mBigWindowView != null) {
            if (mobileRecvSpeed >= 0d) {
                tvMobileRx.setText(showSpeed(mobileRecvSpeed));
            }
            if (mobileSendSpeed >= 0d) {
                tvMobileTx.setText(showSpeed(mobileSendSpeed));
            }
            if (wlanRecvSpeed >= 0d) {
                tvWlanRx.setText(showSpeed(wlanRecvSpeed));
            }
            if (wlanSendSpeed >= 0d) {
                tvWlanTx.setText(showSpeed(wlanSendSpeed));
            }
        }
        if (mSmallWindowView != null && totalSpeed >= 0d) {
            tvSum.setText(showSpeed(totalSpeed));
        }

    }