当前位置: 首页>>代码示例>>Java>>正文


Java TrafficStats.getMobileRxBytes方法代码示例

本文整理汇总了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();
	
	//���岻��
	//������ȡģ��(���Ͷ���),��Ӫ��(��ͨ,�ƶ�....),(��������)�������ӿ�,���
	//����ע��
	
	
	
}
 
开发者ID:cckevincyh,项目名称:mobilesafe,代码行数:24,代码来源:TrafficActivity.java

示例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)));

}
 
开发者ID:ittianyu,项目名称:MobileGuard,代码行数:20,代码来源:TrafficStatsActivity.java

示例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;
}
 
开发者ID:AlanCheen,项目名称:PracticeDemo,代码行数:27,代码来源:DeviceInfoActivty.java

示例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;
}
 
开发者ID:ddinsight,项目名称:dd-collector,代码行数:22,代码来源:Utils.java

示例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();
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:10,代码来源:ModSmartRadio.java

示例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;
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:16,代码来源:ModSmartRadio.java

示例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();
}
 
开发者ID:sh2zqp,项目名称:MobilePhoneSafeProtector,代码行数:10,代码来源:TrafficMonitoringService.java

示例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();
}
 
开发者ID:sh2zqp,项目名称:MobilePhoneSafeProtector,代码行数:40,代码来源:TrafficMonitoringService.java

示例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();
}
 
开发者ID:GuoJinyu,项目名称:AndroidNetworkSpeed,代码行数:9,代码来源:MyWindowManager.java

示例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);
}
 
开发者ID:antonpinchuk,项目名称:trafficstats-example,代码行数:13,代码来源:main.java

示例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;
}
 
开发者ID:ultrafunk,项目名称:NetInfo,代码行数:10,代码来源:NetworkStateService.java

示例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;
}
 
开发者ID:smartenit-eu,项目名称:smartenit,代码行数:33,代码来源:NetworkStatsReader.java

示例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);

}
 
开发者ID:mridang,项目名称:dashclock-network,代码行数:36,代码来源:TrafficWidget.java

示例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);
		}
 
开发者ID:PowerLab,项目名称:PowerDoctor,代码行数:41,代码来源:ApplicationTrafficList.java

示例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;
}
 
开发者ID:laoyaosniper,项目名称:Mobilyzer,代码行数:22,代码来源:RRCTask.java


注:本文中的android.net.TrafficStats.getMobileRxBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。