Android examples for Android OS:Calendar Event
is Event Already At Calendar
//package com.java2s; import java.util.Date; import android.content.Context; import android.database.Cursor; import android.net.Uri; public class Main { public static long isAlreadyAtCalendar(Context context, long stTime, long enTime, String tittleP) { Cursor cursor = context.getContentResolver().query( Uri.parse("content://com.android.calendar/events"), new String[] { "_id", "title", "description", "dtstart", "dtend", "eventLocation", "deleted", }, null, null, null);/*from w ww .ja va 2 s . co m*/ cursor.moveToFirst(); // fetching calendars name String CNames[] = new String[cursor.getCount()]; // fetching calendars id int cont = 0; for (int i = 0; i < CNames.length; i++) { String eid = cursor.getString(0); String desc = cursor.getString(2); String title = cursor.getString(1); Date mDate = new Date(cursor.getLong(3)); Date nDate = new Date(cursor.getLong(4)); long mTime = mDate.getTime(); long lTime = nDate.getTime(); if (stTime <= mTime && enTime >= lTime && tittleP.contains(title.trim())) { cursor.close(); return Long.valueOf(eid); } CNames[i] = cursor.getString(1); cursor.moveToNext(); } cursor.close(); return -1; } }