Android examples for Android OS:Calendar Event
print Calendar Event Instances
import android.annotation.TargetApi; import android.content.ContentResolver; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.DatabaseUtils; import android.net.Uri; import android.os.Build; import android.provider.CalendarContract; import android.util.Log; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; public class Main{ private static final String TAG = CalendarUtil.class.getSimpleName(); public static void printEventInstances(Context context) { // Specify the date range you want to search for recurring // event instances Calendar beginTime = Calendar.getInstance(); beginTime.set(2014, Calendar.APRIL, 1, 5, 0); long startMillis = beginTime.getTimeInMillis(); Calendar endTime = Calendar.getInstance(); endTime.set(2014, Calendar.APRIL, 2, 8, 0); long endMillis = endTime.getTimeInMillis(); Cursor cursor;/* www . j a v a2 s . co m*/ ContentResolver cr = context.getContentResolver(); // Construct the query with the desired date range. Uri.Builder builder = CalendarContract.Instances.CONTENT_URI .buildUpon(); ContentUris.appendId(builder, startMillis); ContentUris.appendId(builder, endMillis); cursor = cr.query(builder.build(), null, null, null, null); String cursorContent = DatabaseUtils.dumpCursorToString(cursor); if (cursor != null) { cursor.close(); } Log.i(TAG, "-------Instances cursorContent: \n" + cursorContent); } }