List of usage examples for android.net TrafficStats UNSUPPORTED
int UNSUPPORTED
To view the source code for android.net TrafficStats UNSUPPORTED.
Click Source Link
From source file:my.home.lehome.fragment.HomeStateFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { }/*from w w w .j a v a 2 s. c o m*/ 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(); }
From source file:edu.cmu.cylab.starslinger.transaction.WebEngine.java
private byte[] doPost(String uri, byte[] requestBody) throws ExchangeException { mCancelable = false;//w w w . j a v a 2 s . co m if (!SafeSlinger.getApplication().isOnline()) { throw new ExchangeException(mCtx.getString(R.string.error_CorrectYourInternetConnection)); } // sets up parameters HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.expect-continue", false); if (mHttpClient == null) { mHttpClient = new CheckedHttpClient(params, mCtx); } HttpPost httppost = new HttpPost(uri); BasicResponseHandler responseHandler = new BasicResponseHandler(); byte[] reqData = null; HttpResponse response = null; long startTime = SystemClock.elapsedRealtime(); int statCode = 0; String statMsg = ""; String error = ""; try { // Execute HTTP Post Request httppost.addHeader("Content-Type", "application/octet-stream"); httppost.setEntity(new ByteArrayEntity(requestBody)); mTxTotalBytes = requestBody.length; final long totalTxBytes = TrafficStats.getTotalTxBytes(); final long totalRxBytes = TrafficStats.getTotalRxBytes(); if (totalTxBytes != TrafficStats.UNSUPPORTED) { mTxStartBytes = totalTxBytes; } if (totalRxBytes != TrafficStats.UNSUPPORTED) { mRxStartBytes = totalRxBytes; } response = mHttpClient.execute(httppost); reqData = responseHandler.handleResponse(response).getBytes("8859_1"); } catch (UnsupportedEncodingException e) { error = e.getLocalizedMessage() + " (" + e.getClass().getSimpleName() + ")"; } catch (HttpResponseException e) { // this subclass of java.io.IOException contains useful data for // users, do not swallow, handle properly statCode = e.getStatusCode(); statMsg = e.getLocalizedMessage(); error = (String.format(mCtx.getString(R.string.error_HttpCode), statCode) + ", \'" + statMsg + "\'"); } catch (java.io.IOException e) { // just show a simple Internet connection error, so as not to // confuse users error = mCtx.getString(R.string.error_CorrectYourInternetConnection); } catch (RuntimeException e) { error = e.getLocalizedMessage() + " (" + e.getClass().getSimpleName() + ")"; } catch (OutOfMemoryError e) { error = mCtx.getString(R.string.error_OutOfMemoryError); } finally { long msDelta = SystemClock.elapsedRealtime() - startTime; if (response != null) { StatusLine status = response.getStatusLine(); if (status != null) { statCode = status.getStatusCode(); statMsg = status.getReasonPhrase(); } } MyLog.d(TAG, uri + ", " + requestBody.length + "b sent, " + (reqData != null ? reqData.length : 0) + "b recv, " + statCode + " code, " + msDelta + "ms"); } if (!TextUtils.isEmpty(error) || reqData == null) { throw new ExchangeException(error); } return reqData; }
From source file:edu.cmu.cylab.starslinger.transaction.WebEngine.java
public long get_txCurrentBytes() { final long totalTxBytes = TrafficStats.getTotalTxBytes(); if (totalTxBytes != TrafficStats.UNSUPPORTED) { mTxCurrentBytes = totalTxBytes - mTxStartBytes; } else {/* w ww. j a va 2s . co m*/ mTxCurrentBytes = 0; } return mTxCurrentBytes; }
From source file:edu.cmu.cylab.starslinger.transaction.WebEngine.java
public long get_rxCurrentBytes() { final long totalRxBytes = TrafficStats.getTotalRxBytes(); if (totalRxBytes != TrafficStats.UNSUPPORTED) { mRxCurrentBytes = totalRxBytes - mRxStartBytes; } else {//from www .j av a 2s . c om mRxCurrentBytes = 0; } return mRxCurrentBytes; }
From source file:pandroid.agent.PandroidAgentListener.java
/** * Retrieves the number of sent/received bytes using the mobile network *///www. j av a 2 s . c o m private void getDataBytes() { long receiveBytes = TrafficStats.getMobileRxBytes(); long transmitBytes = TrafficStats.getMobileTxBytes(); if (receiveBytes != TrafficStats.UNSUPPORTED && transmitBytes != TrafficStats.UNSUPPORTED) { putSharedData("PANDROID_DATA", "receiveBytes", "" + receiveBytes, "long"); putSharedData("PANDROID_DATA", "transmitBytes", "" + transmitBytes, "long"); } }