thanks a lot Mike On Wed, Mar 14, 2012 at 12:43 PM, Michael Chan <mc...@android.com> wrote:
> Have a look at "Querying a calendar" in the link I gave you and > replace the following: > > Uri uri = Events.CONTENT_URI; > String selection = Events.TITLE + " = ? AND " > + Events.DTSTART + " = ? AND " > + Events.DTEND + " = ?"; > String[] selectionArgs = new String[] {"title", > Long.toString(startTimeInMillis), Long.toString(endTimeInMillis)}; > > In the projection, use Events._ID for the event id. > > > On Tue, Mar 13, 2012 at 11:47 PM, giles ian <gilesian....@gmail.com> > wrote: > > Thanks Mike you your answer. > > > > Now my question is how do i check if a particular event is already > present. > > > > Basically i want a select with where clause (for title,start date and end > > date) > > > > > > On Wed, Mar 14, 2012 at 12:01 AM, Michael Chan <mc...@android.com> > wrote: > >> > >> Hi Giles, > >> > >> The code below will add an event every time onClick is called since > >> it's doing an insert(). If you want to modify an existing event, you > >> need to get the event id via a query then do an update. Search for > >> "Updating Events" in > >> > http://developer.android.com/guide/topics/providers/calendar-provider.html > >> > >> Thanks, > >> Mike > >> > >> On Tue, Mar 13, 2012 at 7:28 AM, giles ian <gilesian....@gmail.com> > wrote: > >> > Hi, > >> > > >> > I am using the below code for adding events. > >> > > >> > Now the issue is im able to add same event (all details same) multiple > >> > times. > >> > > >> > How to i avoid this. > >> > > >> > > >> >>> > >> >>> public static void addToCalendar(Context ctx, final String title, > >> >>> > >> >>> final long dtstart, final long dtend) { > >> >>> > >> >>> final ContentResolver cr = ctx.getContentResolver(); > >> >>> > >> >>> Cursor cursor; > >> >>> > >> >>> if (Integer.parseInt(Build.VERSION.SDK) >= 8) > >> >>> > >> >>> cursor = cr.query( > >> >>> > >> >>> Uri.parse("content://com.android.calendar/calendars"), > >> >>> > >> >>> new String[] { "_id", "displayname" }, null, null, null); > >> >>> > >> >>> else > >> >>> > >> >>> cursor = cr.query(Uri.parse("content://calendar/calendars"), > >> >>> > >> >>> new String[] { "_id", "displayname" }, null, null, null); > >> >>> > >> >>> if (cursor.moveToFirst()) { > >> >>> > >> >>> final String[] calNames = new String[cursor.getCount()]; > >> >>> > >> >>> final int[] calIds = new int[cursor.getCount()]; > >> >>> > >> >>> for (int i = 0; i < calNames.length; i++) { > >> >>> > >> >>> calIds[i] = cursor.getInt(0); > >> >>> > >> >>> calNames[i] = cursor.getString(1); > >> >>> > >> >>> cursor.moveToNext(); > >> >>> > >> >>> } > >> >>> > >> >>> > >> >>> AlertDialog.Builder builder = new AlertDialog.Builder(ctx); > >> >>> > >> >>> builder.setSingleChoiceItems(calNames, -1, > >> >>> > >> >>> new DialogInterface.OnClickListener() { > >> >>> > >> >>> > >> >>> @Override > >> >>> > >> >>> public void onClick(DialogInterface dialog, int which) { > >> >>> > >> >>> ContentValues cv = new ContentValues(); > >> >>> > >> >>> cv.put("calendar_id", calIds[which]); > >> >>> > >> >>> cv.put("title", title); > >> >>> > >> >>> cv.put("dtstart", dtstart); > >> >>> > >> >>> cv.put("hasAlarm", 1); > >> >>> > >> >>> cv.put("dtend", dtend); > >> >>> > >> >>> > >> >>> Uri newEvent; > >> >>> > >> >>> if (Integer.parseInt(Build.VERSION.SDK) >= 8) > >> >>> > >> >>> newEvent = cr.insert( > >> >>> > >> >>> Uri.parse("content://com.android.calendar/events"), > >> >>> > >> >>> cv); > >> >>> > >> >>> else > >> >>> > >> >>> newEvent = cr.insert( > >> >>> > >> >>> Uri.parse("content://calendar/events"), > >> >>> > >> >>> cv); > >> >>> > >> >>> > >> >>> if (newEvent != null) { > >> >>> > >> >>> long id = Long.parseLong(newEvent > >> >>> > >> >>> .getLastPathSegment()); > >> >>> > >> >>> ContentValues values = new ContentValues(); > >> >>> > >> >>> values.put("event_id", id); > >> >>> > >> >>> values.put("method", 1); > >> >>> > >> >>> values.put("minutes", 0); // 15 minuti > >> >>> > >> >>> if (Integer.parseInt(Build.VERSION.SDK) >= 8) > >> >>> > >> >>> cr.insert( > >> >>> > >> >>> Uri.parse("content://com.android.calendar/reminders"), > >> >>> > >> >>> values); > >> >>> > >> >>> else > >> >>> > >> >>> cr.insert( > >> >>> > >> >>> Uri.parse("content://calendar/reminders"), > >> >>> > >> >>> values); > >> >>> > >> >>> > >> >>> } > >> >>> > >> >>> dialog.cancel(); > >> >>> > >> >>> } > >> >>> > >> >>> > >> >>> }); > >> >>> > >> >>> > >> >>> builder.create().show(); > >> >>> > >> >>> } > >> >>> > >> >>> cursor.close(); > >> >>> > >> >>> } > >> > > >> > -- > >> > You received this message because you are subscribed to the Google > >> > Groups "Android Developers" group. > >> > To post to this group, send email to > android-developers@googlegroups.com > >> > To unsubscribe from this group, send email to > >> > android-developers+unsubscr...@googlegroups.com > >> > For more options, visit this group at > >> > http://groups.google.com/group/android-developers?hl=en > >> > >> -- > >> You received this message because you are subscribed to the Google > >> Groups "Android Developers" group. > >> To post to this group, send email to > android-developers@googlegroups.com > >> To unsubscribe from this group, send email to > >> android-developers+unsubscr...@googlegroups.com > >> For more options, visit this group at > >> http://groups.google.com/group/android-developers?hl=en > > > > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Developers" group. > > To post to this group, send email to android-developers@googlegroups.com > > To unsubscribe from this group, send email to > > android-developers+unsubscr...@googlegroups.com > > For more options, visit this group at > > http://groups.google.com/group/android-developers?hl=en > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en