我已经建立了成功地使用下面的数据上传到parse.com带宽监控应用:解析和存储数据的实时
testObject.put("dataOutput", String.valueOf(mStartTX));
但是数据始终存储为零。其原因是我发送IS为0的长/字符串的初始值(当应用程序第一次启动时),但是随着用户开始发送和接收数据,它不断变化。这个数据可以实时解析吗?或者随着数据变化每隔几秒就会怨恨?
完整的源:
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);
我对这一切都非常陌生。我刚刚阅读了以下教程:http://www.vogella.com/articles/AndroidServices/article.html,我想我理解一般概念,但在此场景中实现它的确切方式 - 我不知道... –
像这样看起来正确吗?Intent intent = new Intent(this,MyService.class); PendingIntent pintent = PendingIntent.getService(this,0,intent,0); AlarmManager alarm =(AlarmManager)getSystemService(Context.ALARM_SERVICE); alarm.setRepeating(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),1 * 1000,pintent); –
它工作吗? ;)有很多方法可以实现我指出的目标。 –