本文整理汇总了Java中android.net.TrafficStats.UNSUPPORTED属性的典型用法代码示例。如果您正苦于以下问题:Java TrafficStats.UNSUPPORTED属性的具体用法?Java TrafficStats.UNSUPPORTED怎么用?Java TrafficStats.UNSUPPORTED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.net.TrafficStats
的用法示例。
在下文中一共展示了TrafficStats.UNSUPPORTED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNetSpeed
/**
* 得到网络速度
*
* @param context
* @return
*/
public String getNetSpeed(Context context) {
long lastTotalRxBytes = 0;
long lastTimeStamp = 0;
String netSpeed = "0 kb/s";
long nowTotalRxBytes = TrafficStats.getUidRxBytes(context.getApplicationInfo().uid) ==
TrafficStats.UNSUPPORTED ? 0 : (TrafficStats.getTotalRxBytes() / 1024);//转为KB;
long nowTimeStamp = System.currentTimeMillis();
long speed = ((nowTotalRxBytes - lastTotalRxBytes) * 1000 / (nowTimeStamp - lastTimeStamp));//毫秒转换
lastTimeStamp = nowTimeStamp;
lastTotalRxBytes = nowTotalRxBytes;
netSpeed = String.valueOf(speed) + " kb/s";
return netSpeed;
}
示例2: run
@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);
}
示例3: addSample
/**
* Method for polling for the change in total bytes since last update and
* adding it to the BandwidthManager.
*/
protected void addSample() {
long newBytes = -1;
newBytes = TrafficStats.getUidRxBytes(Process.myUid());
if (newBytes == TrafficStats.UNSUPPORTED) {
newBytes = TrafficStats.getTotalRxBytes();
}
long byteDiff = newBytes - sPreviousBytes;
if (sPreviousBytes >= 0) {
synchronized (this) {
long curTimeReading = SystemClock.elapsedRealtime();
mConnectionClassManager.addBandwidth(byteDiff, curTimeReading - mLastTimeReading);
mLastTimeReading = curTimeReading;
}
}
sPreviousBytes = newBytes;
}
示例4: onCreate
@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();
}
示例5: getMobleTraffic
/**
* 获取应用使用的流量
*
* @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";
}
}
示例6: fetchValues
private boolean fetchValues() {
stats[0] = TrafficStats.getMobileRxPackets();
if (stats[0] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetPacketsService.getMetricInfo - mobile rx not supported");
return false;
}
stats[1] = TrafficStats.getMobileTxPackets();
if (stats[1] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetPacketsService.getMetricInfo - mobile tx not supported");
return false;
}
stats[2] = TrafficStats.getTotalRxPackets();
if (stats[2] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetPacketsService.getMetricInfo - total rx not supported");
return false;
}
stats[3] = TrafficStats.getTotalTxPackets();
if (stats[3] == TrafficStats.UNSUPPORTED) {
if (DebugLog.DEBUG) Log.d(TAG, "NetPacketsService.getMetricInfo - total tx not supported");
return false;
}
return true;
}
示例7: onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvSupported = (TextView) findViewById(R.id.tvSupported);
tvDataUsageWiFi = (TextView) findViewById(R.id.tvDataUsageWiFi);
tvDataUsageMobile = (TextView) findViewById(R.id.tvDataUsageMobile);
tvDataUsageTotal = (TextView) findViewById(R.id.tvDataUsageTotal);
if (TrafficStats.getTotalRxBytes() != TrafficStats.UNSUPPORTED && TrafficStats.getTotalTxBytes() != TrafficStats.UNSUPPORTED) {
handler.postDelayed(runnable, 0);
initAdapter();
lvApplications = (ListView) findViewById(R.id.lvInstallApplication);
lvApplications.setAdapter(adapterApplications);
} else {
tvSupported.setVisibility(View.VISIBLE);
}
}
示例8: start
@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;
}
示例9: start
@Override
public int start() {
if ((trafficRxStart = TrafficStats.getTotalRxBytes()) == TrafficStats.UNSUPPORTED) {
return SERVICE_NOT_SUPPORTED;
}
running = true;
trafficTxStart = TrafficStats.getTotalTxBytes();
return SERVICE_START_OK;
}
示例10: getNetSpeed
public static String getNetSpeed(Context context) {
String netSpeed = "0 kb/s";
long nowTotalRxBytes = TrafficStats.getUidRxBytes(context.getApplicationInfo().uid) == TrafficStats.UNSUPPORTED ? 0 : (TrafficStats.getTotalRxBytes() / 1024);//转为KB;
long nowTimeStamp = System.currentTimeMillis();
long speed = ((nowTotalRxBytes - lastTotalRxBytes) * 1000 / (nowTimeStamp - lastTimeStamp));//毫秒转换
lastTimeStamp = nowTimeStamp;
lastTotalRxBytes = nowTotalRxBytes;
netSpeed = String.valueOf(speed) + " kb/s";
return netSpeed;
}
示例11: updateData
@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)");
}
}
示例12: reset
public void reset() {
startTotalBytes = 0;
lastTotalBytes = TrafficStats.UNSUPPORTED;
lastTotalTxBytes = TrafficStats.UNSUPPORTED;
lastTotalRxBytes = TrafficStats.UNSUPPORTED;
refreshPeriod = 1000;
reqStop = false;
}
示例13: onPostExecute
@Override
protected void onPostExecute(Long[] params)
{
if (appWidgetManager!=null&&remoteViews!=null)
appWidgetManager.updateAppWidget(widget, remoteViews);
if (params[0]!=TrafficStats.UNSUPPORTED&¶ms[1]!=TrafficStats.UNSUPPORTED)
{
if (remoteViews!=null&&appWidgetManager!=null&&context!=null)
handler.postDelayed(runnable,1000);
}
}
示例14: run
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: get_txCurrentBytes
public long get_txCurrentBytes() {
final long totalTxBytes = TrafficStats.getTotalTxBytes();
if (totalTxBytes != TrafficStats.UNSUPPORTED) {
mTxCurrentBytes = totalTxBytes - mTxStartBytes;
} else {
mTxCurrentBytes = 0;
}
return mTxCurrentBytes;
}