我已經建立了成功地使用下面的數據上傳到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); –
它工作嗎? ;)有很多方法可以實現我指出的目標。 –