Note that there are some explanatory texts on larger screens.

plurals
  1. POPosting Android Data to Server: Always Results in The Value "0" Being Posted
    primarykey
    data
    text
    <p>I'm attempting to capture and post (bandwith) data from my app every few seconds however every time I parse the data it shows up as 0. Im able to successfully view the values I'm looking for changing on the android device's screen in realtime (the amount of data sent and received) however when I attempt to parse them out to the server. I continually get a zero value posted - instead of the value for the current amount of data sent or received. At first I thought I might be using the incorrect long value (mStartTX) however even when I changed it to "txBytes" it is still appearing as a zero value. </p> <p>I simply need help parsing the value for the current bytes sent and received - but I cannot seem to do so. </p> <p>The initial value of mStartTX is 0 but I think I should be able to capture it's value by using txBytes - but both are showing as having a value of zero when arriving at the server - even though they appear on screen as dynamically changing values (which I'm trying to capture.) </p> <p>I think I'm sending the wrong value to the server - but I'm really not sure. </p> <p>P.S. I've also tried sending other values:</p> <pre><code>testObject.put("DataO", String.valueOf(textRssi)); testObject.put("DataI", String.valueOf(textSpeed)); </code></pre> <p>However they appear as null instead of zero. For some reason I cannot seem to post any of my dynamically changing data... and I do not understand why. </p> <p>SERVER SCREENSHOT:</p> <p><a href="https://docs.google.com/file/d/0B7v2rXEILF-aWnRUUlZEMkxQRm8/edit?usp=sharing" rel="nofollow">https://docs.google.com/file/d/0B7v2rXEILF-aWnRUUlZEMkxQRm8/edit?usp=sharing</a></p> <p>SOURCE: Service_class.java</p> <pre><code>public class Service_class extends Service { TextView textSsid, textSpeed, textRssi; public Handler mHandler = new Handler(); public long mStartRX = 0; public long mStartTX = 0; public long txBytes; public void onCreate(Bundle savedInstanceState) { super.onCreate(); textSsid = (TextView) findViewById(R.id.Ssid); textSpeed = (TextView) findViewById(R.id.Speed); textRssi = (TextView) findViewById(R.id.Rssi); Long.toString(mStartTX); Long.toString(mStartRX); Long.toString(txBytes); mStartRX = TrafficStats.getTotalRxBytes(); mStartTX = TrafficStats.getTotalTxBytes(); if (mStartRX == TrafficStats.UNSUPPORTED || mStartTX == TrafficStats.UNSUPPORTED) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Uh Oh!"); alert.setMessage("Your device does not support traffic stat monitoring."); alert.show(); } else { mHandler.postDelayed(mRunnable, 1000); } } private TextView findViewById(int speed) {= return null; } private final Runnable mRunnable = new Runnable() { public void run() { TextView RX = (TextView)findViewById(R.id.RX); TextView TX = (TextView)findViewById(R.id.TX); long rxBytes = TrafficStats.getTotalRxBytes()- mStartRX; RX.setText(Long.toString(rxBytes)); long txBytes = TrafficStats.getTotalTxBytes()- mStartTX; TX.setText(Long.toString(txBytes)); mHandler.postDelayed(mRunnable, 1000); ParseObject testObject = new ParseObject("TestObject"); testObject.put("DataOut", String.valueOf(txBytes)); testObject.put("DataIn", String.valueOf(mStartRX)); testObject.put("DataRSSI", String.valueOf(textRssi)); testObject.put("DataSpeed", String.valueOf(textSpeed)); testObject.saveInBackground(); final Chronometer myChronometer = (Chronometer)findViewById(R.id.chronometer); myChronometer.start(); DisplayWifiState(); this.registerReceiver(this.myWifiReceiver, new IntentFilter( ConnectivityManager.CONNECTIVITY_ACTION)); } private Chronometer findViewById(int chronometer) { return null; } private void registerReceiver(BroadcastReceiver myWifiReceiver2, IntentFilter intentFilter) { } private BroadcastReceiver myWifiReceiver = new BroadcastReceiver() { @Override public void onReceive(Context arg0, Intent arg1) { NetworkInfo networkInfo = (NetworkInfo) arg1 .getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { DisplayWifiState(); } } }; public void DisplayWifiState() { ConnectivityManager myConnManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo myNetworkInfo = myConnManager .getNetworkInfo(ConnectivityManager.TYPE_WIFI); WifiManager myWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo myWifiInfo = myWifiManager.getConnectionInfo(); if (myNetworkInfo.isConnected()) { textSsid.setText(myWifiInfo.getSSID()); textSpeed.setText(String.valueOf(myWifiInfo.getLinkSpeed()) + " " + WifiInfo.LINK_SPEED_UNITS); textRssi.setText(String.valueOf(myWifiInfo.getRssi())); } else { textSsid.setText("---"); textSpeed.setText("---"); textRssi.setText("---"); }}}; @Override public IBinder onBind(Intent arg0) { return null; } @Override public int onStartCommand(Intent intent, int flags, int startId) { Toast.makeText(this, "Hello World", Toast.LENGTH_LONG).show(); Log.d(TAG, "starting service"); ParseObject testObject = new ParseObject("TestObject"); testObject.put("DataOut", String.valueOf(txBytes)); testObject.put("DataIn", String.valueOf(mStartRX)); testObject.put("DataRSSI", String.valueOf(textRssi)); testObject.put("DataSpeed", String.valueOf(textSpeed)); testObject.saveInBackground(); return START_STICKY; } @Override public void onDestroy() { super.onDestroy(); Toast.makeText(this, "Service Stopped", Toast.LENGTH_LONG).show(); } @Override public void onCreate() { super.onCreate(); } } </code></pre> <p>Data Appears in the server in the following manner:</p> <pre><code>DataIn: Appears as 0 every 12 seconds DataOut Appears as 0 every 12 seconds DataRSSI Appears as null every 12 seconds DataSpeed Appears as null every 12 seconds </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload