此事件已在我的Google日历中创建,但未按代码发出通知。它应该在活动开始时发出通知。代码中提到的所有条目都在日历中被重新选择,事件已经创建,日历显示为alrm:在事件发生时,但仍然没有发出通知。 请帮帮我?
public long MyCalendar() {
long calID = 1;
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
beginTime.set(2015, 4, 29, 10, 51);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(2015, 4, 29, 8, 45);
endMillis = endTime.getTimeInMillis();
String eventUriStr = "content://com.android.calendar/events";
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.TITLE, "My party1");
values.put(CalendarContract.Events.DESCRIPTION, "surprise party");
values.put(CalendarContract.Events.CALENDAR_ID, calID);
TimeZone tz = TimeZone.getDefault();
values.put(CalendarContract.Events.EVENT_TIMEZONE,tz.getID());
values.put(CalendarContract.Events.DTSTART, startMillis);
values.put(CalendarContract.Events.DTEND, endMillis);
Uri uri = cr.insert(Uri.parse(eventUriStr), values);
long eventID = Long.parseLong(uri.getLastPathSegment());
return eventID;
}
**And In onCreate() method of MainActivity, I am calling MyCalendar()**
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
long event_id1= MyCalendar();
ContentResolver cr1 = getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Reminders.MINUTES, 0);
values.put(CalendarContract.Reminders.EVENT_ID, event_id1);
values.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);
MainActivity.this.getContentResolver().insert(CalendarContract.Reminders.CONTENT_URI, values);
}
答案 0 :(得分:0)
我遇到了同样的问题。我注意到如果给出0值:values.put(CalendarContract.Reminders.MINUTES, 0);
没有通知。如果你给0以外的任何一个,那么通知就会出现。
values.put(CalendarContract.Reminders.MINUTES, 1);