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


Java TrafficStats.getUidTxBytes方法代码示例

本文整理汇总了Java中android.net.TrafficStats.getUidTxBytes方法的典型用法代码示例。如果您正苦于以下问题:Java TrafficStats.getUidTxBytes方法的具体用法?Java TrafficStats.getUidTxBytes怎么用?Java TrafficStats.getUidTxBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.net.TrafficStats的用法示例。


在下文中一共展示了TrafficStats.getUidTxBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import android.net.TrafficStats; //导入方法依赖的package包/类
@Override
public void run() {

    double totalBytesReceived = TrafficStats.getUidRxBytes(uid);
    double totalBytesSent = TrafficStats.getUidTxBytes(uid);

    if (totalBytesReceived == TrafficStats.UNSUPPORTED || totalBytesSent == TrafficStats.UNSUPPORTED) {
        Log.w(TAG, "The use of TrafficStats is not supported on this device.");
        return;
    }

    if (previousReceived >= 0 && previousSent >= 0) {
        received = (totalBytesReceived - previousReceived) / intervalSeconds;
        sent = (totalBytesSent - previousSent) / intervalSeconds;
        notifyObservers();
    }
    previousReceived = totalBytesReceived;
    previousSent = totalBytesSent;

    handler.postDelayed(this, intervalMilliseconds);
}
 
开发者ID:Manabu-GT,项目名称:DebugOverlay-Android,代码行数:22,代码来源:NetStatsDataModule.java

示例2: 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

示例3: close

import android.net.TrafficStats; //导入方法依赖的package包/类
public final void close()
  throws IOException
{
  try
  {
    super.close();
    long l4;
    long l5;
    long l6;
    Object[] arrayOfObject2;
    return;
  }
  finally
  {
    long l1 = SystemClock.elapsedRealtime() - NetworkStatsEntity.this.mProcessingStartTime;
    long l2 = TrafficStats.getUidTxBytes(NetworkStatsEntity.this.mUid);
    long l3 = TrafficStats.getUidRxBytes(NetworkStatsEntity.this.mUid);
    Object[] arrayOfObject1 = new Object[5];
    arrayOfObject1[0] = NetworkStatsEntity.this.mUa;
    arrayOfObject1[1] = Long.valueOf(NetworkStatsEntity.this.mResponseLatency);
    arrayOfObject1[2] = Long.valueOf(l1);
    arrayOfObject1[3] = Long.valueOf(l2 - NetworkStatsEntity.this.mStartTx);
    arrayOfObject1[4] = Long.valueOf(l3 - NetworkStatsEntity.this.mStartRx);
    EventLog.writeEvent(52001, arrayOfObject1);
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:27,代码来源:NetworkStatsEntity.java

示例4: onCreate

import android.net.TrafficStats; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
    }
    mStartRX = TrafficStats.getUidRxBytes(mUid);
    mStartTX = TrafficStats.getUidTxBytes(mUid);
    if (mStartRX == TrafficStats.UNSUPPORTED || mStartTX == TrafficStats.UNSUPPORTED) {
        AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
        alert.setTitle("Uh Oh!");
        alert.setMessage("Your device does not support traffic stat monitoring.");
        alert.show();
        return;
    }
    mUid = android.os.Process.myUid();
}
 
开发者ID:legendmohe,项目名称:LEHomeMobile_android,代码行数:17,代码来源:HomeStateFragment.java

示例5: getMobleTraffic

import android.net.TrafficStats; //导入方法依赖的package包/类
/**
 * 获取应用使用的流量
 * 
 * @return
 */
private String getMobleTraffic() {
	long mobleTraffic = 0L;
	int uid = getAppUid();
	if (uid == -1) {
		return "0.00M";
	} else {
		mobleTraffic = (TrafficStats.getUidRxBytes(uid) == TrafficStats.UNSUPPORTED) ? 0
				: TrafficStats.getUidRxBytes(uid);
		mobleTraffic += (TrafficStats.getUidTxBytes(uid) == TrafficStats.UNSUPPORTED) ? 0
				: TrafficStats.getUidTxBytes(uid);
		String traffic = mobleTraffic / (float) (1024 * 1024) + "M";
		return traffic.substring(0, traffic.indexOf(".") + 3) + "M";
	}

}
 
开发者ID:justingboy,项目名称:CouldBooks,代码行数:21,代码来源:ReadstatisticsActivity.java

示例6: update

import android.net.TrafficStats; //导入方法依赖的package包/类
public void update() {
    long delta_tx = TrafficStats.getUidTxBytes(app.uid) - tx;
    long delta_rx = TrafficStats.getUidRxBytes(app.uid) - rx;

    tx = TrafficStats.getUidTxBytes(app.uid);
    rx = TrafficStats.getUidRxBytes(app.uid);

    current_tx = current_tx + delta_tx;
    current_rx = current_rx + delta_rx;

    if(isMobil == true) {
        mobil_tx = mobil_tx + delta_tx;
        mobil_rx = mobil_rx + delta_rx;
    } else {
        wifi_tx = wifi_tx + delta_tx;
        wifi_rx = wifi_rx + delta_rx;
    }
}
 
开发者ID:antonpinchuk,项目名称:trafficstats-example,代码行数:19,代码来源:ApplicationItem.java

示例7: current

import android.net.TrafficStats; //导入方法依赖的package包/类
/**
 * 计算当前流量
 *
 * @param context Context
 * @param tag     traffic tag
 * @return received bytes
 */
public static long current(Context context, String tag) {
    Long appRxValue = sReceivedBytes.get(tag);
    Long appTxValue = sSendBytes.get(tag);
    if (appRxValue == null || appTxValue == null) {
        if (DEBUG) {
            LogUtils.w(TAG, "current() appRxValue or appTxValue is null.");
        }
        return 0;
    }
    final int uid = getUid(context);
    long appRxValue2 = TrafficStats.getUidRxBytes(uid);
    long appTxValue2 = TrafficStats.getUidTxBytes(uid);
    long rxValue = appRxValue2 - appRxValue;
    long txValue = appTxValue2 - appTxValue;
    if (DEBUG) {
        LogUtils.v(TAG, "current() rxValue=" + rxValue / 1000 + " txValue=" + txValue / 1000 + " uid=" + uid);
    }
    return rxValue;

}
 
开发者ID:mcxiaoke,项目名称:Android-Next,代码行数:28,代码来源:TrafficUtils.java

示例8: stop

import android.net.TrafficStats; //导入方法依赖的package包/类
/**
 * 统计TAG流量
 *
 * @param context Context
 * @param tag     traffic tag
 * @return received bytes
 */
public static long stop(Context context, String tag) {
    Long appRxValue = sReceivedBytes.remove(tag);
    Long appTxValue = sSendBytes.remove(tag);
    if (appRxValue == null || appTxValue == null) {
        if (DEBUG) {
            LogUtils.w(TAG, "stop() appRxValue or appTxValue is null.");
        }
        return 0;
    }
    final int uid = getUid(context);
    long appRxValue2 = TrafficStats.getUidRxBytes(uid);
    long appTxValue2 = TrafficStats.getUidTxBytes(uid);
    long rxValue = appRxValue2 - appRxValue;
    long txValue = appTxValue2 - appTxValue;
    if (DEBUG) {
        LogUtils.v(TAG, "stop() rxValue=" + rxValue / 1000 + " txValue=" + txValue / 1000 + " uid=" + uid);
    }
    return rxValue;

}
 
开发者ID:mcxiaoke,项目名称:Android-Next,代码行数:28,代码来源:TrafficUtils.java

示例9: setEndTrafficCounter

import android.net.TrafficStats; //导入方法依赖的package包/类
/**
 * 
 */
private void setEndTrafficCounter() {
	if (USE_PROCESS_UID_FOR_TRAFFIC_MEASUREMENT) {
		this.trafficRxEnd = TrafficStats.getUidRxBytes(processUid);
		this.trafficTxEnd = TrafficStats.getUidTxBytes(processUid);			
	}
	else {
		this.trafficRxEnd = TrafficStats.getTotalRxBytes();
		this.trafficTxEnd = TrafficStats.getTotalTxBytes();			
	}
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:14,代码来源:WebsiteTestServiceImpl.java

示例10: start

import android.net.TrafficStats; //导入方法依赖的package包/类
@Override
public int start() {
	uid = Process.myUid();
	if ((trafficRxStart = TrafficStats.getUidRxBytes(uid)) == TrafficStats.UNSUPPORTED) {
		return SERVICE_NOT_SUPPORTED;
	}		
	
	running = true;
	trafficTxStart = TrafficStats.getUidTxBytes(uid);
	return SERVICE_START_OK;
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:12,代码来源:TrafficServiceByUidImpl.java

示例11: stop

import android.net.TrafficStats; //导入方法依赖的package包/类
@Override
public void stop() {
	if (running) {
		trafficTxEnd = TrafficStats.getUidTxBytes(uid);
		trafficRxEnd = TrafficStats.getUidRxBytes(uid);
	}
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:8,代码来源:TrafficServiceByUidImpl.java

示例12: updateData

import android.net.TrafficStats; //导入方法依赖的package包/类
@SuppressLint("SetTextI18n")
private void updateData() {
    if (App.MiamPlayerConnection == null) {
        return;
    }
    long diff = new Date().getTime() - App.MiamPlayerConnection.getStartTime();
    String dateFormat = String.format(Locale.US, "%02d:%02d:%02d",
            TimeUnit.MILLISECONDS.toHours(diff),
            TimeUnit.MILLISECONDS.toMinutes(diff) % 60,
            TimeUnit.MILLISECONDS.toSeconds(diff) % 60
    );
    tv_time.setText(dateFormat);

    int uid = getActivity().getApplicationInfo().uid;

    if (TrafficStats.getUidRxBytes(uid) == TrafficStats.UNSUPPORTED) {
        tv_traffic.setText(R.string.connection_traffic_unsupported);
    } else {
        String tx = Utilities.humanReadableBytes(
                TrafficStats.getUidTxBytes(uid) - App.MiamPlayerConnection.getStartTx(), true);
        String rx = Utilities.humanReadableBytes(
                TrafficStats.getUidRxBytes(uid) - App.MiamPlayerConnection.getStartRx(), true);

        long total = TrafficStats.getUidTxBytes(uid) - App.MiamPlayerConnection.getStartTx() +
                TrafficStats.getUidRxBytes(uid) - App.MiamPlayerConnection.getStartRx();
        long a = total / TimeUnit.MILLISECONDS.toSeconds(diff);
        String perSecond = Utilities.humanReadableBytes(a, true);

        tv_traffic.setText(tx + " / " + rx + " (" + perSecond + "/s)");
    }
}
 
开发者ID:MBach,项目名称:Miam-Player-remote,代码行数:32,代码来源:ConnectionFragment.java

示例13: getUidTxBytes

import android.net.TrafficStats; //导入方法依赖的package包/类
@Test
public void getUidTxBytes() throws Exception {
    double val = TrafficSampler.getUidTxBytes(2);
    assertEquals(val,101,0);

    PowerMockito.verifyStatic(times(2));
    TrafficStats.getUidTxBytes(2);
}
 
开发者ID:weexteam,项目名称:weex-analyzer-android,代码行数:9,代码来源:TrafficSamplerTest.java

示例14: waitForNetworkUpdate

import android.net.TrafficStats; //导入方法依赖的package包/类
private void waitForNetworkUpdate(long idleTimeoutMillis, long globalTimeoutMillis) {
	final long startTimeMillis = SystemClock.uptimeMillis();
	long prevTraffic = TrafficStats.getUidTxBytes(uid) + TrafficStats.getUidRxBytes(uid);
	boolean idleDetected = false;
	long totTraffic = 0;

	while (!idleDetected) {
		final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
		final long remainingTimeMillis = globalTimeoutMillis - elapsedTimeMillis;
		if (remainingTimeMillis <= 0) {
			Util.err("NO_IDLE_TIMEOUT: " + globalTimeoutMillis);
			break;
		}

		try {
			Thread.sleep(idleTimeoutMillis);
			long currTraffic = TrafficStats.getUidTxBytes(uid) + TrafficStats.getUidRxBytes(uid);
			long delta = currTraffic - prevTraffic;
			if (delta > 0) {
				totTraffic += delta;
				prevTraffic = currTraffic;
			} else { // idle detected
				idleDetected = true;
			}
		} catch (InterruptedException ie) {
			/* ignore */
		}
	}

	if (idleDetected) {
		Util.log("Traffic: " + totTraffic);
	}
}
 
开发者ID:MagicHry,项目名称:EnhancedPUMA,代码行数:34,代码来源:LaunchApp.java

示例15: getCurrentUidTxBytes

import android.net.TrafficStats; //导入方法依赖的package包/类
@CalledByNative
private static long getCurrentUidTxBytes()
{
  long l = TrafficStats.getUidTxBytes(Process.myUid());
  if (l != -1L) {
    return l;
  }
  return 0L;
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:10,代码来源:AndroidTrafficStats.java


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