안드로이드 개발 질문/답변
(글 수 45,052)
브로드캐스트 리시버에 android.intent.action.DATE_CHANGED 를 인텐트로 주어서 캐치하려고 했는데
날짜가 바뀌어도 안 잡하네요...
구글링을 해봐도 이 액션에 대해서는 정보도 없고 잘 안 쓰이는 것 같은데...
날짜가 바뀌는 것을 체크할 수 있는 또 다른 방법이 있을까요?
현재 리시버에 줄 수 있는 액션이 있으면 가장 편한데...
매초 시간을 체크하는 그런 거 말구요
2012.07.04 14:00:16
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
AlarmManager amBeforeSet = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent;
PendingIntent sender;
intent = new Intent(Main.this, Receiver.class);
sender = PendingIntent.getBroadcast(Main.this, 0, intent, 0);
amBeforeSet.cancel(sender);
amBeforeSet.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
24 * 60 * 60 * 1000, sender);
이렇게 해봤는데 이렇게 하면 매일 정각을 캐치할 수 있으려나요
혹시 잘못 된 부분이나 불안한 요소 있으면 알려주세요




요로코롬 시간을 저장해 두었다가 날짜로 비교하고 사용하면 됩니다.
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
Date date = new Date();
date.setTime(currentTime);
String currentDate = df.format(date);
date.setTime(lastConnect);
String lastDate = df.format(date);
// 같은 날 확인 ..
if (currentDate.compareTo(lastDate) != 0) {}