Burhanuddin Rashid Burhanuddin Rashid - 1 year ago 196
Android Question

Reminder/Events is not being Notified

I want to set Reminder and events in android

by using below code i am able to see the events in android calendar but that event is not being notify or being alarm or anything.I am using
for specific time.My problem is reminder and events are not notify or alarmed .Is there a problem in code or something else ?

btnSetAlarm.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
TimePickerDialog timePickerDialog = new TimePickerDialog(getActivity(), new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker timePicker, int hours, int minutes) {


}, hour, minute, false);

private void setReminders(Long eventID) {

Calendar calendar=Calendar.getInstance();
ContentResolver cr = getActivity().getContentResolver();
ContentValues reminders = new ContentValues();
reminders.put(CalendarContract.Reminders.EVENT_ID, eventID);
reminders.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALARM);
Uri eventsUri = Uri.parse("content://com.android.calendar/reminders");
// event is added
cr.insert(eventsUri, reminders);

private void setEvents(int hours, int minutes) {

Calendar calNow = Calendar.getInstance();
Calendar calSet = (Calendar) calNow.clone();

calSet.set(Calendar.HOUR_OF_DAY, hours);
calSet.set(Calendar.MINUTE, minutes);
calSet.set(Calendar.SECOND, 0);
calSet.set(Calendar.MILLISECOND, 0);

ContentResolver cr = getActivity().getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.DTSTART, calSet.getTimeInMillis());
values.put(CalendarContract.Events.DTEND, calSet.getTimeInMillis() + 10000 );
values.put(CalendarContract.Events.TITLE, "My Title");
values.put(CalendarContract.Events.DESCRIPTION, "Android Development");
values.put(CalendarContract.Events.CALENDAR_ID, 1);
values.put(CalendarContract.Events.EVENT_TIMEZONE, Calendar.getInstance().getTimeZone().getID());

Uri eventsUri = Uri.parse("content://com.android.calendar/events");
// event is added
Uri uri=cr.insert(eventsUri, values);

// get the Event ID That is the Last element in the Uri
Long eventID = Long.parseLong(uri.getLastPathSegment());
Log.e(TAG, "" + eventID);


Answer Source

The real issue was with device Redmi Note 2 which does not provide proper BroadcastListner for Calender Events and need enable permission manually from the setting securities and need to set our app in Auto-start mode in order to listner the broadcast hence in short it was device related issue i have verified this code in other device which is working perfectly

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download