當前位置: 首頁>>代碼示例>>Java>>正文


Java TrafficStats.UNSUPPORTED屬性代碼示例

本文整理匯總了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;
}
 
開發者ID:hushengjun,項目名稱:FastAndroid,代碼行數:24,代碼來源:BaseTool.java

示例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);
}
 
開發者ID:Manabu-GT,項目名稱:DebugOverlay-Android,代碼行數:21,代碼來源:NetStatsDataModule.java

示例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;
}
 
開發者ID:WeiDianzhao1989,項目名稱:AndroidAppLib,代碼行數:21,代碼來源:DeviceBandwidthSampler.java

示例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();
}
 
開發者ID:legendmohe,項目名稱:LEHomeMobile_android,代碼行數:16,代碼來源:HomeStateFragment.java

示例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";
	}

}
 
開發者ID:justingboy,項目名稱:CouldBooks,代碼行數:20,代碼來源:ReadstatisticsActivity.java

示例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;
}
 
開發者ID:Sean1988,項目名稱:CIMON_Android,代碼行數:23,代碼來源:NetPacketsService.java

示例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);
    }
}
 
開發者ID:antonpinchuk,項目名稱:trafficstats-example,代碼行數:21,代碼來源:main.java

示例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;
}
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:11,代碼來源:TrafficServiceByUidImpl.java

示例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;
}
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:9,代碼來源:TrafficServiceImpl.java

示例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;
}
 
開發者ID:iPanelkegy,項目名稱:MobileMedia,代碼行數:11,代碼來源:NetUtils.java

示例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)");
    }
}
 
開發者ID:MBach,項目名稱:Miam-Player-remote,代碼行數:31,代碼來源:ConnectionFragment.java

示例12: reset

public void reset() {
    startTotalBytes = 0;
    lastTotalBytes = TrafficStats.UNSUPPORTED;
    lastTotalTxBytes = TrafficStats.UNSUPPORTED;
    lastTotalRxBytes = TrafficStats.UNSUPPORTED;
    refreshPeriod = 1000;
    reqStop = false;
}
 
開發者ID:by-syk,項目名稱:NetUpDown,代碼行數:8,代碼來源:NetTrafficSpider.java

示例13: onPostExecute

@Override
protected void onPostExecute(Long[] params)
{
    if (appWidgetManager!=null&&remoteViews!=null)
        appWidgetManager.updateAppWidget(widget, remoteViews);
    if (params[0]!=TrafficStats.UNSUPPORTED&&params[1]!=TrafficStats.UNSUPPORTED)
    {
        if (remoteViews!=null&&appWidgetManager!=null&&context!=null)
            handler.postDelayed(runnable,1000);
    }
}
 
開發者ID:Daniele-Comi,項目名稱:System-Monitor,代碼行數:11,代碼來源:MobileWidget.java

示例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);
		}
 
開發者ID:PowerLab,項目名稱:PowerDoctor,代碼行數:40,代碼來源:ApplicationTrafficList.java

示例15: get_txCurrentBytes

public long get_txCurrentBytes() {
    final long totalTxBytes = TrafficStats.getTotalTxBytes();
    if (totalTxBytes != TrafficStats.UNSUPPORTED) {
        mTxCurrentBytes = totalTxBytes - mTxStartBytes;
    } else {
        mTxCurrentBytes = 0;
    }
    return mTxCurrentBytes;
}
 
開發者ID:SafeSlingerProject,項目名稱:SafeSlinger-Android,代碼行數:9,代碼來源:WebEngine.java


注:本文中的android.net.TrafficStats.UNSUPPORTED屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。