3

这是从我的应用程序中的按钮调用的。除了通过标题外,它的效果很好。我究竟做错了什么?

public void addCalendarClicked(int position)
    {             
        Intent intent = new Intent(Intent.ACTION_EDIT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra("beginTime", MyStringUtils.dateFromRawTimestamp(_routes[position].getDepartureDateTime()).getTime());
        intent.putExtra("allDay", true);
        intent.putExtra("rrule", "FREQ=YEARLY");
        intent.putExtra("endTime", MyStringUtils.dateFromRawTimestamp(_routes[position].getArrivalDateTime()).getTime());
       intent.putExtra("title", "hello first alarm");

        startActivity(intent);
        }
4

2 回答 2

1
 public void setRemindar(String titleD,String msgD,final String Title ,final String Description,final String day ,final String month,final String year){

                Calendar cal = Calendar.getInstance();     
                Uri EVENTS_URI = Uri.parse(getCalendarUriBase(AlAujairyHoneycombActivity.this) + "events");
                ContentResolver cr = getContentResolver();
                long startMillis = 0; 
                long endMillis = 0; 
                Calendar beginTime = Calendar.getInstance();
                beginTime.set(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day), 9, 0);
                startMillis = beginTime.getTimeInMillis();
                Calendar endTime = Calendar.getInstance();
                endTime.set(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day), 10, 0);
                endMillis = endTime.getTimeInMillis();
                // event insert
                ContentValues values = new ContentValues();
                values.put("calendar_id", 1);
                values.put("title", Title);
                values.put("allDay", 0);
                values.put("dtstart", startMillis ); // event starts at 11 minutes from now
                values.put("dtend", endMillis); // ends 60 minutes from now
                values.put("description", Description);
                values.put("visibility", 0);
                values.put("hasAlarm", 1);
                Uri event = cr.insert(EVENTS_URI, values);
                // reminder insert
                Uri REMINDERS_URI = Uri.parse(getCalendarUriBase(AlAujairyHoneycombActivity.this) + "reminders");
                values = new ContentValues();
                values.put( "event_id", Long.parseLong(event.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;
    }

在清单中

 <uses-permission android:name="android.permission.WRITE_CALENDAR" />
于 2012-06-03T08:15:48.057 回答
1

在您的代码中,您没有将 eventID 附加到 URI...它如何知道要编辑哪个...

long eventID = 208;
Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID); 
Intent intent = new Intent(Intent.ACTION_EDIT) 
    .setData(uri) 
    .putExtra(Events.TITLE, "My New Title"); 
startActivity(intent);

更新 :

你可以试试这个:

Intent intent = new Intent(Intent.ACTION_INSERT)
    .setData(Events.CONTENT_URI) // `content://com.android.calendar/events`
    .putExtra(Events.TITLE, "Yoga")
    .putExtra(Events.DESCRIPTION, "Group class")
    .putExtra(Events.EVENT_LOCATION, "The gym");
startActivity(intent);
于 2012-05-31T08:03:32.860 回答