@Override public void onReceive(Context context, Intent intent) { Options options = null; Bundle bundle = intent.getExtras(); JSONObject args; try { args = new JSONObject(bundle.getString(OPTIONS)); options = new Options(context).parse(args); } catch (JSONException e) { return; } this.context = context; this.options = options; // The context may got lost if the app was not running before LocalNotification.setContext(context); fireTriggerEvent(); if (options.getInterval() == 0) { LocalNotification.unpersist(options.getId()); } else if (isFirstAlarmInFuture()) { return; } else { LocalNotification.add(options.moveDate(), false); } Builder notification = buildNotification(); showNotification(notification); }
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { LocalNotification.webView = super.webView; LocalNotification.context = super.cordova.getActivity().getApplicationContext(); if (action.equalsIgnoreCase("add")) { JSONObject arguments = args.optJSONObject(0); final Options options = new Options(context).parse(arguments); persist(options.getId(), args); cordova .getThreadPool() .execute( new Runnable() { public void run() { add(options); } }); return true; } if (action.equalsIgnoreCase("cancel")) { String id = args.optString(0); cancel(id); unpersist(id); return true; } if (action.equalsIgnoreCase("cancelAll")) { cancelAll(); unpersistAll(); return true; } // Returning false results in a "MethodNotFound" error. return false; }