有很多關於如何在android中創建新日曆事件的例子,但沒有關於如何打開和顯示事件的例子。這是到目前爲止我的代碼在android中打開並顯示日曆事件
public static void startCalendarMimeType(Context context, CalendarItem item){
//all version of android
Intent i = new Intent();
// mimeType will popup the chooser any for any implementing application (e.g. the built in calendar or applications such as "Business calendar"
i.setType("vnd.android.cursor.item/event");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// the time the event should start in millis. This example uses now as the start time and ends in 1 hour
//i.putExtra("beginTime", item.getBegin());
//i.putExtra("endTime", item.getEnd());
i.putExtra("_id", item.getId());
// the action
//i.setAction(Intent.ACTION_PICK);
context.startActivity(i);
}
日曆項目包含使用內容解析器日曆已經檢索到的信息。當用戶點擊我的物品時,我希望它打開顯示物品的Android日曆。
在這一點上,你可以選擇一個應用程序打開,如果你選擇「顯示事件」,它會打開日曆應用程序,但得到一個空指針異常,我只是無法弄清楚我在這裏做錯了什麼。我是第一個嘗試這樣做的人?
任何幫助非常感謝
是真的,但上面的例子對編輯事件有效,但是當我只想查看一個項目時,有些如何給出空指針。這可以做到,只是不知道如何...。 – Alex 2011-03-22 06:30:06