我在找到問題的解決方案時遇到問題。我正在嘗試將多個事件添加到Android日曆中,但我不知道如何。我給找到這段代碼:在Android日曆中插入多個事件
Calendar cal = Calendar.getInstance();
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", cal.getTimeInMillis());
intent.putExtra("allDay", true);
intent.putExtra("rrule", "FREQ=YEARLY");
intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
intent.putExtra("title", "A Test Event from android app"+String.valueOf(i));
startActivity(intent);
,但它所做的是送我到我的日曆,讓我編輯和手動插入我的事件。我想自動插入事件,而不需要去我的日曆應用程序。而且,我只能使用此代碼添加一個事件。這不是我想要的。 我有2個字符串數組,一個包含日期,另一個包含事件的名稱。 有誰知道是否有辦法做到這一點?我一直在尋找一個解決方案很長一段時間,並沒有找到一個。如果有人幫助我,我將不勝感激。謝謝!
我已經解決了這個問題!非常感謝你!但現在我有另一個我無法解決的問題。 我有這樣的代碼:
ContentValues cv = new ContentValues();
cv.put("calendar_id", calIds[0]);
cv.put("title", title);
//cv.put("dtstart", dtstart);
//cv.put("dtend", dtend);
cv.put("rrule", "FREQ=MONTHLY");
cv.put("description", comment);
Calendar start = Calendar.getInstance();
start.set(2012, 0, 2, 8, 0, 0);
Calendar end = Calendar.getInstance();
end.set(2012, 0, 2, 9, 0, 0);
long startTime = start.getTimeInMillis();
long endTime = end.getTimeInMillis();
cv.put("dtstart", startTime);
cv.put("dtend", endTime);
//Insertion on the events of the calendar
cr.insert(Uri.parse("content://com.android.calendar/events"), cv);
它插入我的事件,但它並沒有做到這一點再次發生。我的意思是我的活動出現在2jan2012上,但是2jan2013沒有,2014年也沒有,等等。所以我在手機上打開了我的日曆並試圖編輯我的活動,並且我看到了在哪裏我應該選擇它的出現位置,它顯示在2012年1月2日不在1月2日,因爲它應該是從我的自定義我的活動電話。另一方面,如果我嘗試從我的手機中手動添加事件,它就可以正常工作(我的意思是我可以添加每年發生的事件)。
其實他們終於在ICS加入官方日曆API:http://developer.android.com/reference/android/provider/CalendarContract.html – 2011-12-31 16:11:59
感謝@mbaird,這真是一個好消息!我不在android上工作一段時間,我應該趕上最新版本。 – hago 2011-12-31 17:04:58
我已經解決了這個問題,但現在我又遇到了另一個問題。如果你能再幫我一次,我將非常感激......我編輯了關於另一個問題的問題。 – Lara 2012-01-01 16:39:29