Getting calander events in android 4.0 and above
<p>I am  new to the android development. I am working on calender application where i need to add/delete and get all events in between the date range. I have add and delete the events successufully but problem is when i am getting the calender events in between the date range. I  am getting the calender events but when i go to SPlanner i can see those events are not added in the calender as i have already deleted them. I do not know from where i am getting those events.Please suggest. Here is the code i have written to get the calender events:-</p>

<pre><code>public void onGetEvent (final String fullCallbackName, String title,String startDate,String endDate) throws JSONException
    {
            try
            {
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                final ArrayList&lt;JSONObject&gt; calEvents = new ArrayList();
                 if(calEvents.size() !=0)
                 {
                      calEvents.clear();
                 }

                ContentResolver contentResolver = getContentResolver();
                String selection = "((dtstart &gt;= "+(dateFormat.parse(startDate).getTime())+") AND (dtend &lt;= "+(dateFormat.parse(endDate).getTime())+"))";

                Cursor cursor = contentResolver.query(Uri.parse(getCalendarUriBase() + "events"),
                       (new String[] { "_id", "title", "dtstart","dtend","eventLocation","description"}), selection, null, null);
                Log.e("cursor.getCount before:","callbackFuncName:" +  cursor.getCount());
                while (cursor.moveToNext()) {                       
                     String _id = cursor.getString(0);
                     String displayName = cursor.getString(1);
                        Log.e("cursor.getCount before:","callbackFuncName:" +  displayName);


                     String[] separated = displayName.split(":");
                     if(separated[0]!= null &amp;&amp; title.equals(separated[0]))
                    {
                        JSONObject dictionary =  new JSONObject();

                        String dstart = dateFormat.format(new Date(Long.parseLong(cursor.getString(2))));//cursor.getString(2);    
                        String dEnd = dateFormat.format(new Date(Long.parseLong(cursor.getString(3))));//cursor.getString(3);  
                        String eventlocation = cursor.getString(4);   
                        String description = cursor.getString(5); 
                        dictionary.put("identifier", _id);
                        dictionary.put("title", displayName);
                        dictionary.put("startDate", dstart);
                        dictionary.put("endDate", dEnd);
                        dictionary.put("venue", eventlocation);
                        dictionary.put("notes", description);
                        calEvents.add(dictionary);


                    }
                }

                if(fullCallbackName != null &amp;&amp; !fullCallbackName.equals(""))
                {
                        runOnUiThread(new Runnable() {
                        public void run()
                        {

                            webView.loadUrl("javascript:"+fullCallbackName+" ("+calEvents+")") ; 
                        }
                    });
                }


            }
            catch(Exception e)
            {
            Log.e("string", e.toString());
            }
        }

    }  
</code></pre>

<p>code for getting the calender DB is:-</p>

<pre><code>private String getCalendarUriBase() {
        String calendarUriBase = null;
        Uri calendars = Uri.parse("content://calendar/calendars");
        Cursor cursor = null;
        try {
            cursor = managedQuery(calendars, null, null, null, null);
        } catch (Exception e) {
            // eat
        }

        if (cursor != null) {
            calendarUriBase = "content://calendar/";
        } else {
            calendars = Uri.parse("content://com.android.calendar/calendars");
            try {
                cursor = managedQuery(calendars, null, null, null, null);
            } catch (Exception e) {
                // eat
            }

            if (cursor != null) {
                calendarUriBase = "content://com.android.calendar/";
            }

        }
        Log.d("Sandeep",
                calendarUriBase);
       // managedCursor.close();
        return calendarUriBase;
    }
</code></pre>
