我正在創建一個應用程序來提醒用戶即將到來的約會。我們只需說
用戶預約將在21:9:2016。因此,在任命兩天前警報會開始通知他 目前我知道如何在特定時間設置鬧鐘,但不知道如何設置從1日期到另一日期的鬧鐘。 這是我設定特定日期的鬧鐘的代碼。用於獲取日,小時,月,年的日期時間確定安排鬧鐘的日期和時間
public String getDayofTheMonth(String datetime) {
db = this.DataBase.getReadableDatabase();
String selectQuery = "select strftime('%d','" + datetime + "') as result";
Cursor c = db.rawQuery(selectQuery, null);
if (c.moveToFirst()) {
return c.getString(c.getColumnIndex("result"));
}
return "";
}
public String getSecondFromDateTime(String datetime) {
db = this.DataBase.getReadableDatabase();
String selectQuery = "select strftime('%S','" + datetime + "') as result";
Cursor c = db.rawQuery(selectQuery, null);
if (c.moveToFirst()) {
return c.getString(c.getColumnIndex("result"));
}
return "";
}
public String getMinuteFromDateTime(String datetime) {
db = this.DataBase.getReadableDatabase();
String selectQuery = "select strftime('%M','" + datetime + "') as result";
Cursor c = db.rawQuery(selectQuery, null);
if (c.moveToFirst()) {
return c.getString(c.getColumnIndex("result"));
}
return "";
}
功能從未來的日期歌廳過去的日期
public static void setUpAlarm(Context context, String time, String appointment_id) {
int month = Integer.valueOf(DataBaseManager.getInstance(context).getMonthFromDateTime(time));
int year = Integer.valueOf(DataBaseManager.getInstance(context).getYearFromDateTime(time));
int day = Integer.valueOf(DataBaseManager.getInstance(context).getDayofTheMonth(time));
int hour = Integer.valueOf(DataBaseManager.getInstance(context).getHourFromDateTime(time));
int min = Integer.valueOf(DataBaseManager.getInstance(context).getMinuteFromDateTime(time));
int sec =0;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.clear();
calendar.set(year, --month, day, hour, min, 0);
long sdl = calendar.getTimeInMillis();
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReciver.class);
intent.putExtra("service_id", appointment_id);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, Integer.valueOf(alarmCode), intent, PendingIntent.FLAG_CANCEL_CURRENT);
alarmMgr.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}
// DB函數
public List<String> getPastDatesFromSpecificDate(String noOfDays, String datetime) {
db = this.Database.getReadableDatabase();
List<String> dateslist = new ArrayList<>();
for (int i = -1; i < Integer.valueOf(datetime); i++) {
String selectQuery = "SELECT date('" + datetime + "','-" + i + " day') as datetime; ";
Cursor c = db.rawQuery(selectQuery, null);
if (c.moveToFirst()) {
Log.d("past_dates",c.getString(c.getColumnIndex("datetime")));
dateslist.add(c.getString(c.getColumnIndex("datetime")));
}
}
return dateslist;
}
誰能幫助我?
你能告訴我如何使用報警管理器以上特定任務嗎? –