当前位置: 首页>>代码示例>>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;未经允许,请勿转载。