Example #1
0
        private void messageSaveAndSend() {
          // 获取上次更新的时间
          SharePreferenceUtil sharePreference = SharePreferenceUtil.getInstance(SyncService.this);
          int lastId = sharePreference.getLastMessageId();
          // 获取按照时间由近及远的收件箱短信
          String where = Sms.TYPE + "=" + Sms.MESSAGE_TYPE_INBOX + " AND " + Sms._ID + ">" + lastId;
          Cursor c = getContentResolver().query(smsUri, SMS_PROJECTION, where, null, "date DESC");
          if (c != null && c.moveToFirst()) {
            do {
              if (c.isFirst()) {
                // 记录最近一个更新的ID
                sharePreference.setLastMessageId(c.getInt(c.getColumnIndex(Sms._ID)));
              }
              if (messageCount >= 2) {
                messageCount = 0;
                break;
              }
              messageCount++;
              ShortMessage newShortMessage = new ShortMessage();
              newShortMessage.setUserId(
                  AccountUtils.getCurrentUser(SyncService.this).getObjectId());
              newShortMessage.setFromNumber(c.getString(c.getColumnIndex(Sms.ADDRESS)));
              newShortMessage.setContent(c.getString(c.getColumnIndex(Sms.BODY)));
              newShortMessage.setReceiveTime(c.getLong(c.getColumnIndex(Sms.DATE)));
              LogUtils.d(newShortMessage.getContent());
              // TODO newShortMessage.setUserId();
              // TODO 1,Save,2,Update 做一个保存上传队列
              addMessageUploadTaskToQueue(newShortMessage);
            } while (c.moveToNext());
          }

          closeCursor(c);
        }
Example #2
0
 @Override
 public void onCreate() {
   super.onCreate();
   LogUtils.d("SyncSeevice", "SyncService create");
   getContentResolver().registerContentObserver(smsUri, true, mmSmsDbChangeObserver);
 }