나는이 주제에 관해 많은 질문을하고 있지만 그 중 아무도 내가하려고하는 것에 도움이되지 않는다는 것을 알고 있습니다. 그래서 당신이 저를 도울 수 있기를 바랍니다. 하루 중 서로 다른 시간에 트리거되는 3 개의 알람을 설정하고자하는 경우 오전 9시, 오후 1시, 오후 6시에 대해 잠깐 이야기하십시오. 시간에 대한 정보는 sqlite 데이터베이스에 저장됩니다.3 가지 알람 설정 안드로이드
행을 기준으로 데이터베이스를 읽고 각 시간별로 알람을 설정합니다. 이드는 단지 숫자 만 사용하고 있습니다.
이것은 내가 사용하고있는 코드입니다. 하나의 알람을 설정할 때만 작동하지만 더 설정하려고하면 아무 것도 설정되지 않습니다.
private void setAlarm() throws ParseException {
DBHelper helper = new DBHelper(Main3Activity.this);
Cursor cursor = helper.getQueryDB();
cursor.moveToPosition(-1);
int i = 1;
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
while (cursor.moveToNext()) {
final String name = cursor.getString(1);
final String time = cursor.getString(2);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), i, intent, 0);
Calendar t = parseTime(time);
alarmManager.set(AlarmManager.RTC_WAKEUP, t.getTimeInMillis(), pendingIntent);
i++;
}
}
public Calendar parseTime (String t) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy");
Calendar cal = Calendar.getInstance();
cal.setTime(sdf.parse(t));
return cal;
}
답변을 더 많이 개발할 수 있습니까? 나는 당신이 의미하는 것을 완전히 이해하지 못합니다. – cotita