Java Code Examples for android.net.TrafficStats#getMobileTxBytes()
The following examples show how to use
android.net.TrafficStats#getMobileTxBytes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrafficStatsActivity.java From MobileGuard with MIT License | 6 votes |
/** * 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))); }
Example 2
Source File: DeviceInfoActivty.java From PracticeDemo with Apache License 2.0 | 6 votes |
@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; }
Example 3
Source File: ModSmartRadio.java From GravityBox with Apache License 2.0 | 5 votes |
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(); }
Example 4
Source File: ModSmartRadio.java From GravityBox with Apache License 2.0 | 5 votes |
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; }
Example 5
Source File: MyWindowManager.java From AndroidNetworkSpeed with GNU General Public License v3.0 | 5 votes |
public void initData() { mobileRecvSum = TrafficStats.getMobileRxBytes(); mobileSendSum = TrafficStats.getMobileTxBytes(); wlanRecvSum = TrafficStats.getTotalRxBytes() - mobileRecvSum; wlanSendSum = TrafficStats.getTotalTxBytes() - mobileSendSum; rxtxTotal = TrafficStats.getTotalRxBytes() + TrafficStats.getTotalTxBytes(); }
Example 6
Source File: main.java From trafficstats-example with MIT License | 5 votes |
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); }
Example 7
Source File: RRCTask.java From Mobilyzer with Apache License 2.0 | 5 votes |
/** * 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; }
Example 8
Source File: Device.java From callmeter with GNU General Public License v3.0 | 5 votes |
/** * {@inheritDoc} */ @Override public long getCellTxBytes() throws IOException { final long l = TrafficStats.getMobileTxBytes(); if (l < 0L) { return 0L; } return l; }
Example 9
Source File: Device.java From callmeter with GNU General Public License v3.0 | 5 votes |
/** * {@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; }
Example 10
Source File: RxNetSpeedView.java From RxTools-master with Apache License 2.0 | 4 votes |
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)); } } //============================================================== }
Example 11
Source File: NETUtils.java From GTTools with MIT License | 4 votes |
public static long getNetTxMobileBytes() { long total = TrafficStats.getMobileTxBytes(); return total; }
Example 12
Source File: MyWindowManager.java From AndroidNetworkSpeed with GNU General Public License v3.0 | 4 votes |
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)); } }