조금 질문이 있습니다. AlarmManager를 사용하여 특정 시간에 내 알림을 설정했습니다. 알림을 설정 한 시간은 SQLLite 데이터베이스에 저장됩니다. 그들은 전화를 재부팅 한 순간을 제외하고 모두 완벽하게 작동합니다. alarmManager는 물론 반복합니다.재부팅 후 알람 설정
이 상황에서 가장 좋은 해결책은 무엇입니까? 내 알람 관리기는 MainActivity에 설정하고 아래의 코드에서 볼 수 있듯이 나는 브로드 캐스트 리시버 안에 내 알림을 설정합니다
여기은 내가 MainActivity에서 호출 방법 :
Intent intent = new Intent(context, MyReceiver.class);
intent.putExtra(EXTRA_TITLE, title);
intent.putExtra(EXTRA_COUNT, count);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, count, intent, PendingIntent.FLAG_CANCEL_CURRENT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), WEEK_LENGTH_MS, pendingIntent);
을 그리고 여기에 방송 수신기의 방법이다 onReceive
public void onReceive(Context context, Intent intent)
{
nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = context.getString(R.string.app_name);
CharSequence message = intent.getStringExtra(DayActivity.EXTRA_TITLE);
Intent intentNotification = new Intent(context,DayActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, intent.getIntExtra(DayActivity.EXTRA_COUNT,0), intentNotification, 0);
Notification notif = new Notification(R.drawable.notification_logo,context.getString(R.string.app_name), System.currentTimeMillis());
notif.setLatestEventInfo(context, from, message, contentIntent);
notif.defaults |= Notification.DEFAULT_LIGHTS;
notif.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
nm.notify(intent.getIntExtra(DayActivity.EXTRA_COUNT,0), notif);
}
내가 BOOT_COMPLETED 이벤트를 브로드 캐스트 리시버를 선언하고 있지만, 항상 내가 전화 결코 이상을 시작할 때 단지 빈 통지를 호출합니다.
그래서 OnBootReceiver와 같이 alarmManager를 사용하여 첫 번째 BroadcastReceiver를 호출 할 시간을 얻으시겠습니까? –
@JanOmacka : 예. 하나의'BroadcastReceiver'가 두 역할을 처리하게하는 것은 환영 할 만하지만 들어오는'Intent'의 액션 문자열을 검사하는 것과 같이 부트 이벤트와 알람 이벤트를 구별해야합니다. 예를 들어, [이 샘플 앱] (https://github.com/commonsguy/cw-omnibus/tree/master/AlarmManager/WakeCast)은 'BOOT_COMPLETED'브로드 캐스트가 'null'이 아닌 액션을 갖기 때문에이 방법을 사용합니다 'PendingIntent'와'AlarmManager'에 사용 된 명시적인'Intent'는'null' 액션 문자열을 가질 것입니다. – CommonsWare
도움 주셔서 대단히 감사합니다. –