title: Adding Custom Calendar Events – Phonegap Android plugin
body: <p>Below is my  CalendarEventPlugin.js file:</p>
  
  <pre><code>window.addcalendareventplugin = function(startDate, endDate, allDay, successCallback){     
  //call the Plugin execute method()
  console.log(successCallback,function(err){
  callback('Error: ' + err);      
  },"CalendarEventPlugin","addCalendarEvent",[startDate, endDate, allDay]); 
  }
  </code></pre>
  
  <p>Im using cordova-2.5.0 and Android Version 2.2 and above.</p>
  
  <p>Below is my CalendarEventPlugin.java file:</p>
  
  <pre><code>package org.apache.cordova.plugin;
  
  import java.util.Calendar;
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.apache.cordova.api.CallbackContext;
  import org.apache.cordova.api.CordovaPlugin;
  
  import android.content.Intent;
  import android.provider.CalendarContract;
  import android.provider.CalendarContract.Events;
  
  public class CalendarEventPlugin extends CordovaPlugin {        
      @Override       
      public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {           
              if (action.equals("addCalendarEvent")) {
                      if(data.length() &gt; 0)
                      {
                              //if you are passing some data eg. start,end date, all day and parameters for the Calendar
                              //from plugin's javascript interface then you can retrieve and parse the data from data[] here. 
                             String startDate = data.getString(0);
                      String endDate = data.getString(1);
                      boolean allDay = data.getBoolean(2);                                                        
                              if(this.addCalendarEvent())
                              {
                                      callbackContext.success("Done!!");
                              }
                              else
                              {
                                      callbackContext.error("Error!!");
                              }
                      }                       
                      return true;
              }
              return false;
      }       
  
      private boolean addCalendarEvent(){     
              Boolean ret = false;
              try{
                      Calendar beginTime = Calendar.getInstance(); //the begin time and end time can come from javascript if user enters this values in a form
              beginTime.set(2013, 1, 20, 7, 30);
              Calendar endTime = Calendar.getInstance();
              endTime.set(2013, 1, 20, 8, 30); //set your own time here and above as well or you can get the current time.
  
              Intent intent = new Intent(Intent.ACTION_EDIT);
              intent.setType("vnd.android.cursor.item/event");
              intent.setAction(Intent.ACTION_INSERT);
              intent.putExtra(Events.TITLE, "A new event"); //can come from javascript.
              intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
              intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis());
              intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis());
  
              this.cordova.startActivityForResult(this, intent, 0);
  
              ret = true;
              }
              catch(Exception e){
                      e.printStackTrace();
                      ret = false;
              }
              return ret;
      }       
     }
  </code></pre>
  
  <p>Below is my index file :</p>
  
  <pre><code>     &lt;!DOCTYPE HTML&gt;
       &lt;html&gt;
       &lt;head&gt;
       &lt;title&gt;Cordova&lt;/title&gt;
       &lt;script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"&gt;&lt;/script&gt;
       &lt;script type="text/javascript" charset="utf-8" src="CalenderEventPlugin.js"&gt;           &lt;/script&gt;
       &lt;script type="text/javascript" charset="utf-8" src="app.js"&gt;&lt;/script&gt;
       &lt;/head&gt;
       &lt;body&gt;
       &lt;h4&gt;Custom Plugin Development&lt;/h4&gt;
       &lt;button onclick="test5()"&gt;Calendar Event Plugin&lt;/button&gt;
  
       &lt;br/&gt;
       &lt;/body&gt;
       &lt;/html&gt;
  </code></pre>
  
  <p>Below is my app.js file:</p>
  
  <pre><code>    function test5(){
  //alert("call of app js file");
      window.addcalendareventplugin("2015-09-09T16:00:00-06:00", "2015-09-09T18:00:00-06:00","true",function(val){
      alert(val);   //once success message come and you have tested it, you can remove this alert.
      });
    }
  </code></pre>
  
  <p>I am not able to invoke the addCalenderEvent .I am getting Json Error..
  Can any one please help.
  Thanks in advance..:)</p>