1
此事件已在我的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);
}
後堆棧跟蹤,請... –
它沒有給予任何錯誤@ursgtm – Baqir
你BEGINTIME晚於結束時間。 – Arst