我已经构建了一个带宽监视器应用程序,它使用以下内容成功地将数据上传到 parse.com:
testObject.put("dataOutput", String.valueOf(mStartTX));
但是,数据始终存储为零。原因是我发送的长/字符串的初始值为零(当应用程序首次启动时),但是随着用户开始发送和接收数据,它会不断变化。可以以某种方式实时解析这些数据吗?或者随着数据的变化每隔几秒重新发送一次?
完整来源:
public class ParseStarterProjectActivity extends Activity {
TextView textSsid, textSpeed, textRssi;
public Handler mHandler = new Handler();
public long mStartRX = 0;
public long mStartTX = 0;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.parser);
textSsid = (TextView) findViewById(R.id.Ssid);
textSpeed = (TextView) findViewById(R.id.Speed);
textRssi = (TextView) findViewById(R.id.Rssi);
Long.toString(mStartTX);
ParseAnalytics.trackAppOpened(getIntent());
ParseObject testObject = new ParseObject("TestObject");
testObject.put("dataOutput", String.valueOf(mStartTX));
testObject.saveInBackground();
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 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);