Cannot read records after inserting to google calendar.
Some time letter, records are read.
Why?
If take Context from Activity, then everything works fine. If Context from AndroidTestCase or take on their Application, it does not work.
Note: Calendar with id=calendarId is empty.
public static void test(final Context context, final int calendarId) {
// insert
java.util.Calendar calendar = java.util.Calendar.getInstance();
ContentValues contentValues = new ContentValues();
contentValues.put("calendar_id", calendarId);
contentValues.put("dtstart", calendar.getTime().getTime());
contentValues.put("dtend", calendar.getTime().getTime() + 1L*60*60*1000);
contentValues.put("title", "test_title");
Uri uri = Uri.parse("content://com.android.calendar/events");
context.getContentResolver.insert(uri, contentValues);
// read
Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();
ContentUris.appendId(builder, Long.MIN_VALUE);
ContentUris.appendId(builder, Long.MAX_VALUE);
Cursor cursor = context.getContentResolver.query(
builder.build(),
new String[] { "event_id", "title" },
"Calendars._id=" + calendarId,
null,
null);
try {
if (!cursor.moveToNext()) {
// fail
throw new IllegalStateException();
}
} finally {
cursor.close();
}
}
My mistake. In code:
Can not set start date
Long.MIN_VALUEvalue.