I want to send a notification to the local user at a specific date and time. I am using the alarm manager and Broadcast Receiver for this.
Here I schedule my notification:
private void createNotification (String name, String date) {
int year = Integer.parseInt(date.substring(0,4));
int month = Integer.parseInt(date.substring(4,6));
int day = Integer.parseInt(date.substring(6,8));
int hour = Integer.parseInt(date.substring(8,10));
int min = Integer.parseInt(date.substring(10,12));
AlarmManager mAlarm = (AlarmManager) act.getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.set(year,month,day,hour,min,0);
calendar.add(Calendar.HOUR_OF_DAY, -4);
Intent intent = new Intent("partypooper.DISPLAY_NOTIFICATION");
intent.putExtra("eventName", name);
intent.putExtra("eventDate", hour+":"+min);
PendingIntent broadcast = PendingIntent.getBroadcast(getContext(), 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
mAlarm.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), broadcast);
}
Here is my manifest where I have the receiver for the PendingIntent:
<receiver android:name=".Notification.NotificationReceiver">
<intent-filter>
<action android:name="partypooper.DISPLAY_NOTIFICATION"/>
<action android:name="partypooper.eventName"/>
<action android:name="partypooper.eventTime"/>
</intent-filter>
</receiver>
I then have a class NotificationReceiver which extends BroadcastReceiver where I take action to display the notification inside the onReceive override method. However, this method never gets called for some reason. I have troubleshooted this problem and looked at many similar ways to implement this, however I still can't figure out why it doesn't work
Any help would be appreciated, thanks.