事件详细信息在android日历中保存问题

时间:2012-08-23 13:25:35

标签: android events calendar save

我面对的事件详细信息从长时间保存在Android日历中。我可以在Android 2.2.3版本以下的设备中保存详细信息但是对于上面它不保存到日历。这是我的代码:


            Calendar cal = Calendar.getInstance();  
            Uri events = null;
            if(getCalendarUriBase(this)!=null)
            {   
            Uri EVENTS_URI = Uri.parse(getCalendarUriBase(this) + "events");
            ContentResolver cr = getContentResolver();
            // event insert

             long eventdate1=Date.parse(“23/07/2012”);
             long eventdate2=Date.parse((“23/07/2012”);

            ContentValues values = new ContentValues();
            values.put("calendar_id", 1);
            values.put("title","Event 1");
            values.put("allDay", 0);
            values.put("dtstart", eventdate1); // event starts at 11 minutes from now
            values.put("dtend", eventdate2); // ends 60 minutes from now
            values.put("description", "Description 1");
            values.put("eventLocation", "xyz");
            values.put("visibility", 0);
            values.put("hasAlarm", 1);
            try{
            try{    
            events = cr.insert(EVENTS_URI, values);
            }catch (Exception e) {
                // TODO: handle exception
                return false;
            }
            // reminder insert

            Uri REMINDERS_URI = Uri.parse(getCalendarUriBase(this) + "reminders");
            values = new ContentValues();
            values.put( "event_id", Long.parseLong(events.getLastPathSegment()));
            values.put( "method", 1 );
            values.put( "minutes", 10 );
            cr.insert( REMINDERS_URI, values );

private String getCalendarUriBase(Activity act) {

    String calendarUriBase = null;
    Uri calendars = Uri.parse("content://calendar/calendars");
    Cursor managedCursor = null;
    try {
        managedCursor = act.managedQuery(calendars, null, null, null, null);
    } catch (Exception e) {
    }
    if (managedCursor != null) {
        calendarUriBase = "content://calendar/";
    } else {
        calendars = Uri.parse("content://com.android.calendar/calendars");
        try {
            managedCursor = act.managedQuery(calendars, null, null, null, null);
        } catch (Exception e) {
        }
        if (managedCursor != null) {
            calendarUriBase = "content://com.android.calendar/";
        }
    }
    return calendarUriBase;
}

** * ** *

我遗失的地方。请帮帮我。

1 个答案:

答案 0 :(得分:0)

我有类似的问题。我认为问题在于

values.put("visibility", 0);

我认为数据库中没有该名称的列。名为 transparency 的列也是如此。我在网上的一些教程中找到了它