Reputation: 3273
This is called from a button in my app. It works great except for passing of the title. What am I doing wrong?
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);
}
Upvotes: 3
Views: 523
Reputation: 35946
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;
}
In Manifest
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
Upvotes: 1
Reputation: 24233
In your code you not appending the eventID to the URI... How does it know which one to edit..
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);
You can try this :
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);
Upvotes: 1