Reminder/Events 未收到通知
Reminder/Events is not being Notified
我想通过使用下面的代码在 android Calender
中设置提醒和事件 我能够在 android 日历中看到事件,但该事件没有被通知或正在警报或 anything.I 正在使用 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);
}
真正的问题出在设备 Redmi Note 2 上,它没有为 Calender
事件提供适当的 BroadcastListner
,需要从设置证券中手动启用权限,并且需要在 [=12] 中设置我们的应用程序=] 模式以便收听广播因此简而言之这是与设备相关的问题我已经在其他设备上验证了这个代码,它工作正常
来自文档:
The alarm method, as set on the server. METHOD_DEFAULT, METHOD_ALERT, METHOD_EMAIL, METHOD_SMS and METHOD_ALARM are possible values; the device will only process METHOD_DEFAULT and METHOD_ALERT reminders (the other types are simply stored so we can send the same reminder info back to the server when we make changes).
尝试将 CalendarContract.Reminders.METHOD_ALARM
更改为 CalendarContract.Reminders.METHOD_ALERT
我想通过使用下面的代码在 android Calender
中设置提醒和事件 我能够在 android 日历中看到事件,但该事件没有被通知或正在警报或 anything.I 正在使用 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);
}
真正的问题出在设备 Redmi Note 2 上,它没有为 Calender
事件提供适当的 BroadcastListner
,需要从设置证券中手动启用权限,并且需要在 [=12] 中设置我们的应用程序=] 模式以便收听广播因此简而言之这是与设备相关的问题我已经在其他设备上验证了这个代码,它工作正常
来自文档:
The alarm method, as set on the server. METHOD_DEFAULT, METHOD_ALERT, METHOD_EMAIL, METHOD_SMS and METHOD_ALARM are possible values; the device will only process METHOD_DEFAULT and METHOD_ALERT reminders (the other types are simply stored so we can send the same reminder info back to the server when we make changes).
尝试将 CalendarContract.Reminders.METHOD_ALARM
更改为 CalendarContract.Reminders.METHOD_ALERT