本文整理匯總了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;
}