1
我想通過使用下面的代碼設置Android Calender
中的提醒和事件我能夠看到Android日曆中的事件,但該事件不是通知或正在報警或任何東西。我正在使用timpicker
具體time.My問題是提醒和事件不通知或驚慌。是否有代碼或其他的問題?提醒/事件沒有被通知
btnSetAlarm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
TimePickerDialog timePickerDialog = new TimePickerDialog(getActivity(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int hours, int minutes) {
setEvents(hours,minutes);
}
}, hour, minute, false);
timePickerDialog.show();
}
});
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);
reminders.put(CalendarContract.Reminders.MINUTES,5);
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.HAS_ALARM,1);
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);
setReminders(eventID);
}