-
Notifications
You must be signed in to change notification settings - Fork 15
/
CalendarPlugin.java
51 lines (44 loc) · 1.65 KB
/
CalendarPlugin.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.tenforwardconsulting.phonegap.plugins;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;
import android.app.Activity;
import android.content.Intent;
public class CalendarPlugin extends CordovaPlugin {
public static final String ACTION_ADD_TO_CALENDAR = "addToCalendar";
public static final Integer RESULT_CODE_CREATE = 0;
private CallbackContext callback;
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
try {
if (ACTION_ADD_TO_CALENDAR.equals(action)) {
JSONObject arg_object = args.getJSONObject(0);
callback = callbackContext;
Intent calIntent = new Intent(Intent.ACTION_EDIT)
.setType("vnd.android.cursor.item/event")
.putExtra("beginTime", arg_object.getLong("startTimeMillis"))
.putExtra("endTime", arg_object.getLong("endTimeMillis"))
.putExtra("title", arg_object.getString("title"))
.putExtra("description", arg_object.getString("description"))
.putExtra("eventLocation", arg_object.getString("eventLocation"));
this.cordova.startActivityForResult(this, calIntent, RESULT_CODE_CREATE);
return true;
}
} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
return false;
}
return false;
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == RESULT_CODE_CREATE) {
if(resultCode == Activity.RESULT_OK) {
callback.success();
} else {
callback.error("Activity result code " + resultCode);
}
}
}
}