private void startAlarm() {
AlarmManager alarmMgr;
PendingIntent alarmIntent;
alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(MainActivity.this, AlarmReceiver.class);
alarmIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 52);
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
1000 * 60 * 20, alarmIntent);
}
startAlarm() 메소드는 MainActivity 클래스에 있습니다.알람 관리자 안드로이드
다음 코드 23시 52분에서 (onReceive 선언()는 클래스 AlarmReceiver 방법) 축배 및 20 분 간격으로 표시해야 그 후
AlarmReceiver는 브로드 캐스트 리시버를 확장한다.
코드는 오류없이 컴파일되지만 어떤 이유로 토스트를 표시하지 않습니다.
참고 : 코드는 ELAPSED_REALTIME_WAKEUP으로 정상적으로 작동합니다. RTC_WAKEUP에만 문제가 있습니다. 그래서 다른 모든 것들은 정확해야합니다. startAlarm() 메소드 내부에서만 잘못된 것이 있습니다.
Intent intent = new Intent(MainActivity.this, AlarmReceiver.class);
intent.setAction("YourPackageName.YourAction");
alarmIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0);
그리고 매니페스트에 :
<receiver android:name=".AlarmReciever">
<intent-filter>
<action android:name="YourPackageName.YourAction" />
</intent-filter>
</receiver>
이 문제를 해결해야 당신은 의도 작업을 설정해야처럼
코드가 ELAPSED_REALTIME_WAKEUP에서 제대로 작동합니다. RTC_WAKEUP에만 문제가 있습니다. 그래서 다른 모든 것들은 정확해야합니다. startAlarm() 메소드 내부에서만 잘못된 것이 있습니다. – rayan