Working with the Android Calendar
I am trying to add entry to the Android Calendar(2.2),but i have ever got some error. I tried a lot of test but without success.What is wrong please? Sorry for my english.
Source code:
String calName;
String calId = null;
String[] projection = new String[] { "_id", "name" };
Uri calendars = Uri.parse("content://com.android.calendar/calendars");
Cursor managedCursor = managedQuery(calendars, projection, "selected=1", null, null);
ContentValues event = new ContentValues();
DateFormat date = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
long time = System.currentTimeMillis();
String timeStr = date.format(time);
Lo开发者_高级运维g.d(TAG, "Value of timeStr: " + timeStr);
if (managedCursor.moveToNext()) {
calName = managedCursor.getString(managedCursor.getColumnIndex("name"));
calId = managedCursor.getString(managedCursor.getColumnIndex("_id"));
event.put("calendar_id", calId);
event.put("title", "Event Title");
event.put("description", "Description");
event.put("eventLocation", "New York");
event.put("dtstart", timeStr );
event.put("dtend", timeStr);
Uri eventsUri = Uri.parse("content://com.android.calendar/events");
Uri url = getContentResolver().insert(eventsUri, event);
}
First, please post the StackTrace for your error. Second: before you try managedCursor.moveToNext, use:
managedCursor.moveToFirst();
and then
while(managedCursor.moveToNext()){ };
精彩评论