设置消息发送开始日期时间

时间:2017-12-19 13:05:03

标签: android sqlite sms android-sqlite smsmanager

我有聊天应用程序,我正在向正在发送的号码发送消息。现在我想要我应该设置消息发送的开始日期时间。为此,我在sqlite数据库中存储了datetime。那是我的代码:

while (true) {


            cursor = databaseHelperClass.getMessageNotSent();
            if (cursor != null && cursor.moveToFirst()) {
                do {
                    Id = cursor.getInt(cursor.getColumnIndex("ID"));
                    jobMessageNotSent = cursor.getString(cursor.getColumnIndex("Message"));
                    startDatetime = cursor.getString(cursor.getColumnIndex("StartDatetime"));
                    isComplete = cursor.getInt(cursor.getColumnIndex("isComplete"));
                } while (cursor.moveToNext());
                new SendJobMessages().execute(Id);
            } 

这是我的asyncTask代码:

 private class SendJobMessages extends AsyncTask<Integer , Integer, Integer> {
    private String jobNumbers = null;

    @Override
    protected Integer doInBackground(Integer... jobMessageIds) {
        totalNumbers = jobMessageIds.length;


        jobNumbersArray = new ArrayList<String>();
        databaseHelperClass = new DatabaseHelperClass(getApplicationContext());
        cursor = databaseHelperClass.getMessagesNumber(Id);
        if (cursor != null && cursor.moveToFirst()) {
            do {
                JobMessagesId = cursor.getInt(cursor.getColumnIndex("ID"));
                laterJobsNumbers = cursor.getString(cursor.getColumnIndex("Numbers"));
                JobId = cursor.getInt(cursor.getColumnIndex("JobId"));
                jobNumbersArray.add(laterJobsNumbers);
            } while (cursor.moveToNext());


            // sendJobsMessages();
            for (int i = 0; i < jobNumbersArray.size(); i++) {
                jobNumbers = jobNumbersArray.get(i);
                if (countMessagePerDay() >= Integer.parseInt(MaxNoOfMessagePerDay)) {
                    try {
                        Thread.sleep(10000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {
                    try {

                        sendSMSLater(String.valueOf(jobNumbers));
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    this.publishProgress(1);
                }

            }
        }
        return jobMessageIds.length;
     }

}

这是我的sqlite查询:

public Cursor getJMessagesNotSent() {
    db = this.getReadableDatabase();
    String query = "select * from Jobs where iscomplete = 0 and datetime('now') > startdatetime";
    Cursor cursor = db.rawQuery(query, null);
    return cursor;
}

和数字:

public Cursor getJobsNumber(int jobId) {
    db = this.getReadableDatabase();
    String query = "SELECT * From JobMessages where issent = 0 and JobId = " + jobId + "";
    Cursor cursor = db.rawQuery(query, null);
    return cursor;
}

0 个答案:

没有答案