AlarmManager manager = (AlarmManager) YourContext.getSystemService(Context.ALARM_SERVICE);

/* 알람 설정 */
Intent yourintent = new Intent(YourContext, YourThing.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(YourContext, 0, yourintent, 0);

/* 6:50:00 AM 알람 */
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 6);
calendar.set(Calendar.MINUTE, 50);
calendar.set(Calendar.SECOND, 00);
calendar.set(Calendar.MILLISECOND, 00);

/* 매일 6:50:00 AM 알람 */
manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);

※ 설정 시각보다 조금 늦게 발동할 수도 있음
※ 2016/09/01 - setInexactRepeating() 로 변경


저작자 표시 비영리 변경 금지
신고