I'm building an Android app using PhoneGap (aka Cordova), and am having trouble getting a calendar integration to work. Disclaimer: I'm a noob to both Android and PhoneGap, please bear with me.
All I'm trying to do is add an event to the user's calendar. Following this tutorial, I've created a Plugin that attempts to launch a Calendar Intent. The code looks like this:
public class CalendarPlugin extends Plugin {
public static final String NATIVE_ACTION_STRING="addToCalendar";
public static final String SUCCESS_PARAMETER="success";
@Override
public PluginResult execute(String action, JSONArray data, String callbackId) {
if (NATIVE_ACTION_STRING.equals(action)) {
Calendar beginTime = Calendar.getInstance();
beginTime.set(2012, 6, 19, 7, 30);
Calendar endTime = Calendar.getInstance();
endTime.set(2012, 6, 19, 8, 30);
Intent calIntent = new Intent((Context) this.ctx, CalendarPlugin.class)
.setAction(Intent.ACTION_INSERT)
.putExtra(Events.TITLE, "A new event")
.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true)
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis())
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis());
this.ctx.startActivity(calIntent);
return new PluginResult(PluginResult.Status.OK, "Smashing success");
}
return new PluginResult(PluginResult.Status.ERROR, "Didn't work bro");
}
}
The Javascript code to invoke this plugin is standard:
var CalendarPlugin = {
callNativeFunction: function (success, fail, resultType) {
if (cordova) {
return cordova.exec( success, fail,
"org.myorg.appname.CalendarPlugin",
"addToCalendar", [resultType]);
}
else {
alert("Calendar function is not available here.");
}
}
};
The Android code is getting invoked (confirmed using a breakpoint). But the result sent back to the Javascript code is an error:
Unable to find explicit activity class {org.myorg.appname/org.myorg.appname.CalendarPlugin}; have you declared this activity in your AndroidManifest.xml?
There's no mention of adding to AndroidManifest.xml in the tutorial, which leads me to believe I'm missing something (also, the CalendarPlugin code is being invoked successfully, so how could there be an error saying the CalendarPlugin class could not be found?). If indeed I need to add CalendarPlugin to the manifest, how would I go about doing that?