title: Adding Calendar and events in Android 4.0
body: <p>I want to add calendar events in android 4.0 and above version device. 
  Currently i am adding the events using the following code,</p>
  
  <pre><code>if (android.os.Build.VERSION.SDK_INT &lt;= 7 )
                      {
                          Uri calendars = Uri.parse("content://calendar/calendars");
                          Cursor managedCursor = managedQuery(calendars, projection, null, null, null);
                          if (managedCursor.moveToFirst()) 
                          {
                              String calName; 
                              String calId; 
                              int nameColumn = managedCursor.getColumnIndex("name"); 
                              int idColumn = managedCursor.getColumnIndex("_id");
                              do 
                              {
                                  calName = managedCursor.getString(nameColumn);
                                  calId = managedCursor.getString(idColumn);
                                  Log.e("Calendar Id : ",""+calId+" : "+calName);
                              }
                              while (managedCursor.moveToNext());
  
                              if(calId != null)
                              {
                                  try 
                                  {
                                      Log.e("Calendar Id : ",""+calId+" : "+calName);
                                      ContentValues event = new ContentValues();
                                      event.put("calendar_id", calId);
                                      event.put("title", summary);
                                      event.put("description", summary);
                                      event.put("eventLocation", "");
  
                                      event.put("dtstart", startTime);
                                      event.put("dtend", endTime);
                                      event.put("allDay", allDayFlag);  
                                      event.put("eventStatus", 1);
                                      event.put("visibility", 0);
                                      event.put("hasAlarm", 1); 
                                      Uri eventsUri = Uri.parse("content://calendar/events");
                                      Uri url = getContentResolver().insert(eventsUri, event);
                                      Log.e("Event Res : ",""+url);
                                      if(!url.equals(""))
                                      Main.showErrorDialog(this, "Event Successfully Added ");
                                  }
                                  catch (Exception kwse) 
                                  {
                                      Log.e("Exception 1 kwse ",""+kwse.toString());
                                  }
                              }
                          }
                      }
                      else
                      {
                          Uri calendars= Uri.parse("content://com.android.calendar/calendars");
                          Cursor managedCursor = managedQuery(calendars, projection, null, null, null);
                          if (managedCursor.moveToFirst()) 
                          {
                              String calName; 
                              String calId; 
                              int nameColumn = managedCursor.getColumnIndex("name"); 
                              int idColumn = managedCursor.getColumnIndex("_id");
                              do 
                              {
                                  calName = managedCursor.getString(nameColumn);
                                  calId = managedCursor.getString(idColumn);
                                  Log.e("Calendar Id : ",""+calId+" : "+calName);
                              }
                              while (managedCursor.moveToNext());
  
                              if(calId != null)
                              {
                                  try 
                                  {
                                      Log.e("Calendar Id : ",""+calId+" : "+calName);
                                      ContentValues event = new ContentValues();
                                      event.put("calendar_id", calId);
                                      event.put("title", summary);
                                      event.put("description", summary);
                                      event.put("eventLocation", "");
  
                                      event.put("dtstart", startTime);
                                      event.put("dtend", endTime);
                                      event.put("allDay", allDayFlag);  
                                      event.put("eventStatus", 1);
                                      event.put("visibility", 0);
                                      event.put("hasAlarm", 1); 
                                      Uri eventsUri = Uri.parse("content://com.android.calendar/events");
                                      Uri url = getContentResolver().insert(eventsUri, event);
                                      Log.e("Event Res : ",""+url);
                                      if(!url.equals(""))
                                      Main.showErrorDialog(this, "Event Successfully Added ");
                                  }
                                  catch (Exception kwse) 
                                  {
                                      Log.e("Exception 2 kwse ",""+kwse.toString());
                                  }
                              }
                          }
                      }
  </code></pre>
  
  <p>The above code is running good till android 3.0, but the events are not getting added in android 4.0, this is a complaint i got from my client. I dont have a device of android 4.0, so i am unable to check it.</p>
  
  <p>For android devices of <code>sdk version 7 and below</code> it we use as</p>
  
  <pre><code>Uri calendars = Uri.parse("content://calendar/calendars");
  </code></pre>
  
  <p>where as for <code>sdk version above 7</code> we use as</p>
  
  <pre><code>Uri calendars= Uri.parse("content://com.android.calendar/calendars");
  </code></pre>
  
  <p>Is this is the same for android 4.0 too are anything to be changed ?</p>