本文整理匯總了Java中android.net.TrafficStats.getMobileRxBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java TrafficStats.getMobileRxBytes方法的具體用法?Java TrafficStats.getMobileRxBytes怎麽用?Java TrafficStats.getMobileRxBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.net.TrafficStats
的用法示例。
在下文中一共展示了TrafficStats.getMobileRxBytes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import android.net.TrafficStats; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_traffic);
//��ȡ�ֻ���������
//��ȡ����(R �ֻ�(2G,3G,4G)��������)
long mobileRxBytes = TrafficStats.getMobileRxBytes();
//��ȡ�ֻ���������(�ϴ�+����)
//T total(�ֻ�(2G,3G,4G)������(�ϴ�+����))
long mobileTxBytes = TrafficStats.getMobileTxBytes();
//total(���������ܺ�(�ֻ�+wifi))
long totalRxBytes = TrafficStats.getTotalRxBytes();
//(������(�ֻ�+wifi),(�ϴ�+����))
long totalTxBytes = TrafficStats.getTotalTxBytes();
//���岻��
//������ȡģ��(���Ͷ���),��Ӫ��(��ͨ,�ƶ�....),(��������)�������ӿ�,���
//����ע��
}
示例2: initData
import android.net.TrafficStats; //導入方法依賴的package包/類
/**
* 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)));
}
示例3: handleMessage
import android.net.TrafficStats; //導入方法依賴的package包/類
@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;
}
示例4: getTraffic
import android.net.TrafficStats; //導入方法依賴的package包/類
public static HashMap<String, Long> getTraffic() {
HashMap<String, Long> hashMap = new HashMap<>();
long mobileRxBytes = TrafficStats.getMobileRxBytes();
long mobileTxBytes = TrafficStats.getMobileTxBytes();
long totalRxBytes = TrafficStats.getTotalRxBytes();
long totalTxbytes = TrafficStats.getTotalTxBytes();
long wifiRxbytes = totalRxBytes - mobileRxBytes;
long wifiTxbytes = totalTxbytes - mobileTxBytes;
// total traffic
hashMap.put("totRxB", totalRxBytes);
hashMap.put("totTxB", totalTxbytes);
// mobile traffic
hashMap.put("mobRxB", mobileRxBytes);
hashMap.put("mobTxB", mobileTxBytes);
return hashMap;
}
示例5: scheduleAlarm
import android.net.TrafficStats; //導入方法依賴的package包/類
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();
}
示例6: shouldPostponeAlarm
import android.net.TrafficStats; //導入方法依賴的package包/類
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;
}
示例7: onCreate
import android.net.TrafficStats; //導入方法依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
mOldRxBytes = TrafficStats.getMobileRxBytes();
mOldTxBytes = TrafficStats.getMobileTxBytes();
dao = new TrafficDao(this);
preferences = getSharedPreferences("config",MODE_PRIVATE);
mThread.start();
}
示例8: updateTodayGPRS
import android.net.TrafficStats; //導入方法依賴的package包/類
private void updateTodayGPRS() {
//獲取已經使用了的流量
usedFlow = preferences.getLong("usedflow",0);
Date date = new Date();
Calendar c = Calendar.getInstance();
c.setTime(date);
if (c.DAY_OF_MONTH == 1 && c.HOUR_OF_DAY == 0
&&c.MINUTE < 1 && c.SECOND <30) {
usedFlow = 0;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dataString = sdf.format(date);
long mobileGPRS = dao.getMobileGPRS(dataString);
long mobileRxBytes = TrafficStats.getMobileRxBytes();
long mobileTxBytes = TrafficStats.getMobileTxBytes();
//新產生的流量
long newGPRS = (mobileRxBytes+mobileTxBytes) - mOldTxBytes - mOldRxBytes;
mOldTxBytes = mobileTxBytes;
mOldRxBytes = mobileRxBytes;
if (newGPRS < 0) {
//網絡切換過
newGPRS = mobileRxBytes + mobileTxBytes;
}
if (mobileGPRS == -1) {
dao.insertTodayGPRS(newGPRS);
} else {
if (mobileGPRS<0) {
mobileGPRS = 0;
}
dao.UpdateTodayGPRS(mobileGPRS+newGPRS);
}
usedFlow = usedFlow + newGPRS;
SharedPreferences.Editor editor = preferences.edit();
editor.putLong("usedflow",usedFlow);
editor.apply();
}
示例9: initData
import android.net.TrafficStats; //導入方法依賴的package包/類
public void initData() {
mobileRecvSum = TrafficStats.getMobileRxBytes();
mobileSendSum = TrafficStats.getMobileTxBytes();
wlanRecvSum = TrafficStats.getTotalRxBytes() - mobileRecvSum;
wlanSendSum = TrafficStats.getTotalTxBytes() - mobileSendSum;
rxtxTotal = TrafficStats.getTotalRxBytes()
+ TrafficStats.getTotalTxBytes();
}
示例10: run
import android.net.TrafficStats; //導入方法依賴的package包/類
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);
}
示例11: setGetDataUsageBytes
import android.net.TrafficStats; //導入方法依賴的package包/類
public static long setGetDataUsageBytes()
{
long dataUsageBytes = TrafficStats.getMobileRxBytes() + TrafficStats.getMobileTxBytes();
if (dataUsageBytes > 0 )
NetworkStateService.dataUsageBytes = dataUsageBytes;
return dataUsageBytes;
}
示例12: read
import android.net.TrafficStats; //導入方法依賴的package包/類
public static interfaces[] read() {
interfaces[] result = new interfaces[2];
// get current values of counters
long currentMobileTxBytes = TrafficStats.getMobileTxBytes();
long currentMobileRxBytes = TrafficStats.getMobileRxBytes();
long totalTxBytes = TrafficStats.getTotalTxBytes() - oldTxBytes;
long totalRxBytes = TrafficStats.getTotalRxBytes() - oldRxBytes;
// get WiFi data count, subtract total from mobile
long currentNetworkSent = totalTxBytes
- (currentMobileTxBytes - oldMobileTxBytes);
long currentNetworkReceived = totalRxBytes
- (currentMobileRxBytes - oldMobileRxBytes);
result[0] = new interfaces();
result[0].setPacketsrx(currentMobileRxBytes - oldMobileRxBytes);
result[0].setPacketstx(currentMobileTxBytes - oldMobileTxBytes);
result[0].setMac("ee:ee:ee:ee");
result[1] = new interfaces();
result[1].setPacketsrx(currentNetworkReceived);
result[1].setPacketstx(currentNetworkSent);
result[1].setMac("ff:ff:ff:ff");
oldTxBytes = TrafficStats.getTotalTxBytes();
oldRxBytes = TrafficStats.getTotalRxBytes();
oldMobileTxBytes = currentMobileTxBytes;
oldMobileRxBytes = currentMobileRxBytes;
return result;
}
示例13: onUpdateData
import android.net.TrafficStats; //導入方法依賴的package包/類
@Override
protected void onUpdateData(int intReason) {
Log.d(getTag(), "Calculating the amount of data transferred");
ExtensionData edtInformation = new ExtensionData();
setUpdateWhenScreenOn(true);
try {
ComponentName cmpActivity = new ComponentName("com.android.settings", "com.android.settings.Settings$DataUsageSummaryActivity");
Long lngMobile = this.lngMobile + TrafficStats.getMobileRxBytes() + TrafficStats.getMobileTxBytes();
Long lngTotal = this.lngTotal + TrafficStats.getTotalRxBytes() + TrafficStats.getTotalTxBytes();
Long lngWifi = lngTotal - lngMobile;
String strMobile = Formatter.formatFileSize(getApplicationContext(), lngMobile);
String strTotal = Formatter.formatFileSize(getApplicationContext(), lngTotal);
String strWifi = Formatter.formatFileSize(getApplicationContext(), lngWifi);
edtInformation.expandedTitle(String.format(getString(R.string.status), strTotal));
edtInformation.status(strTotal);
edtInformation.expandedBody(String.format(getString(R.string.message), strMobile, strWifi));
edtInformation.visible(true);
edtInformation.clickIntent(new Intent().setComponent(cmpActivity));
} catch (Exception e) {
edtInformation.visible(false);
Log.e(getTag(), "Encountered an error", e);
ACRA.getErrorReporter().handleSilentException(e);
}
edtInformation.icon(R.drawable.ic_dashclock);
doUpdate(edtInformation);
}
示例14: run
import android.net.TrafficStats; //導入方法依賴的package包/類
public void run() {
// 3G통신의 데이터 RX(수신) KByte 값이다.
if (TrafficStats.getMobileRxBytes() == TrafficStats.UNSUPPORTED) {
MemTotal.setText("UNSUPPORTED!");
} else {
MemTotal.setText(MemoryFormat.format(TrafficStats
.getMobileRxBytes() / 1024)
+ "KB");
}
// 3G통신의 데이터 TX(송신) KByte 값이다.
if (TrafficStats.getMobileTxBytes() == TrafficStats.UNSUPPORTED) {
MemFree.setText("UNSUPPORTED!");
} else {
MemFree.setText(MemoryFormat.format(TrafficStats
.getMobileTxBytes() / 1024)
+ "KB");
}
// WIFI 통신의 데이터 RX(수신) KByte 값이다.
if (TrafficStats.getTotalRxBytes() == TrafficStats.UNSUPPORTED) {
mWIFIRxtext.setText("UNSUPPORTED!");
} else {
mWIFIRxtext.setText(MemoryFormat.format(TrafficStats
.getTotalRxBytes() / 1024)
+ "KB");
}
// WIFI 통신의 데이터 TX(송신) KByte 값이다.
if (TrafficStats.getTotalTxBytes() == TrafficStats.UNSUPPORTED) {
mWIFITxtext.setText("UNSUPPORTED!");
} else {
mWIFITxtext.setText(MemoryFormat.format(TrafficStats
.getTotalTxBytes() / 1024)
+ "KB");
}
appList2 = activityManager.getRunningAppProcesses();
RunProcess.setText(""+appList2.size());
// 0.05초 마다 핸들러를 발생 시키기 때문에 응답성을 매우 높일 수가 있다.
uiHandler.postDelayed(this, 50);
}
示例15: 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;
}