List of usage examples for org.apache.cordova PluginResult PluginResult
public PluginResult(Status status, List<PluginResult> multipartMessages)
From source file:com.appfeel.cordova.analytics.CPGoogleAnalytics.java
License:Open Source License
private PluginResult execTrackPromotion(JSONObject options, CallbackContext callbackContext) { PluginResult result = new PluginResult(Status.ERROR, "Missing promotion id or promotion name"); if (tracker == null) { result = new PluginResult(Status.ERROR, "Tracker not started. Call startTrackerWithId('UA-XXXXXX'); first."); } else if (options.has(OPT_PROMOTION_ID) || options.has(OPT_PROMOTION_NAME)) { Promotion promotion = new Promotion(); ProductAction productAction = createProductAction(options); if (options.has(OPT_PROMOTION_ID)) { promotion.setId(options.optString(OPT_PROMOTION_ID)); }/*from www.jav a 2s . com*/ if (options.has(OPT_PROMOTION_NAME)) { promotion.setName(options.optString(OPT_PROMOTION_NAME)); } if (options.has(OPT_PROMOTION_CREATIVE)) { promotion.setCreative(options.optString(OPT_PROMOTION_CREATIVE)); } if (options.has(OPT_PROMOTION_POSITION)) { promotion.setPosition(options.optString(OPT_PROMOTION_POSITION)); } if (options.has(OPT_PRODUCT_SCREEN_NAME)) { tracker.setScreenName(options.optString(OPT_PRODUCT_SCREEN_NAME)); } if (options.has(OPT_CATEGORY) && options.has(OPT_ACTION)) { HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder(); prepareBuilder(builder, options); builder.setCategory(options.optString(OPT_CATEGORY)); builder.setAction(options.optString(OPT_ACTION)); if (options.has(OPT_LABEL)) { builder.setLabel(options.optString(OPT_LABEL)); } if (options.has(OPT_VALUE)) { builder.setValue(options.optLong(OPT_VALUE)); } builder.addPromotion(promotion); if (productAction != null) { builder.setProductAction(productAction); } tracker.send(builder.build()); } else { HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder(); prepareBuilder(builder, options); builder.addPromotion(promotion); if (productAction != null) { builder.setProductAction(productAction); } tracker.send(builder.build()); } tracker.setScreenName(actualScreen); result = new PluginResult(Status.OK); } return result; }
From source file:com.appfeel.cordova.analytics.CPGoogleAnalytics.java
License:Open Source License
private PluginResult execTrackSocial(JSONObject options, CallbackContext callbackContext) { PluginResult result = new PluginResult(Status.ERROR, "Missing network, action or target"); if (tracker == null) { result = new PluginResult(Status.ERROR, "Tracker not started. Call startTrackerWithId('UA-XXXXXX'); first."); } else if (options.has(OPT_NETWORK) && options.has(OPT_ACTION) && options.has(OPT_TARGET)) { HitBuilders.SocialBuilder builder = new HitBuilders.SocialBuilder(); prepareBuilder(builder, options); builder.setNetwork(options.optString(OPT_NETWORK)); builder.setAction(options.optString(OPT_ACTION)); builder.setTarget(options.optString(OPT_TARGET)); tracker.send(builder.build());//from w w w .j a va 2s . co m result = new PluginResult(Status.OK); } return result; }
From source file:com.appfeel.cordova.analytics.CPGoogleAnalytics.java
License:Open Source License
private PluginResult execSetCampaignFromUrl(String uriString, CallbackContext callbackContext) { PluginResult result = new PluginResult(Status.ERROR, "Missing url string"); if (null != uriString && uriString.length() > 0) { this.campaignUrl = uriString; result = new PluginResult(Status.OK); }/*from w w w . j a v a2 s. c om*/ return result; }
From source file:com.appfeel.cordova.analytics.CPGoogleAnalytics.java
License:Open Source License
private PluginResult execSetUserId(String userId, CallbackContext callbackContext) { PluginResult result = new PluginResult(Status.ERROR, "Missing user id"); if (tracker == null) { result = new PluginResult(Status.ERROR, "Tracker not started. Call startTrackerWithId('UA-XXXXXX'); first."); } else if (null != userId && userId.length() > 0) { tracker.set("&uid", userId); result = new PluginResult(Status.OK); }/* w w w . j a v a2 s . c o m*/ return result; }
From source file:com.arsmentis.cordova.jdbc.Jdbc.java
License:Apache License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if ("connect".equals(action)) { String url = args.getString(0); String user = args.getString(1); String password = args.getString(2); try {// w ww .ja v a 2s . com connect(url, user, password); callbackContext.success(); } catch (SQLException e) { callbackContext.error(e.toString()); } return true; } else if ("disconnect".equals(action)) { try { disconnect(); callbackContext.success(); } catch (SQLException e) { callbackContext.error(e.toString()); } return true; } else if ("execute".equals(action)) { String sql = args.getString(0); try { JSONArray results = execute(sql); callbackContext.success(results); } catch (SQLException e) { callbackContext.error(e.toString()); } catch (JSONException e) { callbackContext.error(e.toString()); } return true; } else if ("load".equals(action)) { String driver = args.getString(0); try { Class.forName(driver); callbackContext.success(); } catch (ClassNotFoundException e) { callbackContext.error(e.toString()); } return true; } else if ("isConnected".equals(action)) { try { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, isConnected())); } catch (SQLException e) { callbackContext.error(e.toString()); } return true; } return false; }
From source file:com.ayogo.cordova.notification.NotificationPlugin.java
License:Apache License
@Override public boolean execute(String action, final JSONArray args, final CallbackContext callback) { if (action.equals("requestPermission")) { callback.sendPluginResult(new PluginResult(PluginResult.Status.OK, "granted")); return true; }/*w ww. j av a2 s . co m*/ if (action.equals("showNotification")) { cordova.getThreadPool().execute(new Runnable() { public void run() { try { String title = args.getString(0); JSONObject options = args.getJSONObject(1); if (options.optString("tag", null) == null) { options.put("tag", callback.getCallbackId()); } LOG.v(TAG, "Schedule Notification: " + title); mgr.scheduleNotification(title, options); callback.sendPluginResult(new PluginResult(PluginResult.Status.OK)); } catch (JSONException ex) { callback.sendPluginResult( new PluginResult(PluginResult.Status.ERROR, "Missing or invalid title or options")); } } }); return true; } if (action.equals("closeNotification")) { cordova.getThreadPool().execute(new Runnable() { public void run() { try { String tag = args.getString(0); LOG.v(TAG, "cancel Notification: " + tag); mgr.cancelNotification(tag); callback.sendPluginResult(new PluginResult(PluginResult.Status.OK)); } catch (JSONException ex) { callback.sendPluginResult( new PluginResult(PluginResult.Status.ERROR, "Missing or invalid title or options")); } } }); return true; } if (action.equals("getNotifications")) { cordova.getThreadPool().execute(new Runnable() { public void run() { LOG.v(TAG, "Get Notifications"); JSONArray notifications = mgr.getNotifications(); // Android doesn't require permission to send push notifications callback.sendPluginResult(new PluginResult(PluginResult.Status.OK, notifications)); } }); return true; } LOG.i(TAG, "Tried to call " + action + " with " + args.toString()); callback.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); return false; }
From source file:com.ayogo.cordova.push.PushPlugin.java
License:Apache License
@Override public boolean execute(String action, JSONArray args, final CallbackContext callback) { if (action.equals("registerPush") || action.equals("getPushRegistration")) { cordova.getThreadPool().execute(new Runnable() { public void run() { try { String deviceToken = FirebaseInstanceId.getInstance().getToken(mSenderID, FirebaseMessaging.INSTANCE_ID_SCOPE); callback.sendPluginResult( new PluginResult(PluginResult.Status.OK, wrapRegistrationData(deviceToken))); } catch (IOException ex) { callback.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "AbortError")); }//from ww w . j av a2s . c o m } }); return true; } if (action.equals("unregisterPush")) { cordova.getThreadPool().execute(new Runnable() { public void run() { try { FirebaseInstanceId.getInstance().deleteToken(mSenderID, FirebaseMessaging.INSTANCE_ID_SCOPE); callback.sendPluginResult(new PluginResult(PluginResult.Status.OK)); } catch (IOException ex) { callback.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "AbortError")); } } }); return true; } if (action.equals("hasPermission")) { // Android doesn't require permission to send push notifications callback.sendPluginResult(new PluginResult(PluginResult.Status.OK, "granted")); return true; } LOG.i(TAG, "Tried to call " + action + " with " + args.toString()); callback.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); return false; }
From source file:com.blackberry.community.SimpleXpBeaconPlugin.java
License:Apache License
private void monitorSuccessResponse(CallbackContext callbackContext) throws JSONException { // {"desc":"...","status":"OK"} JSONObject response = new JSONObject(); response.put(JSON_KEY_DESCRIPTION, JSON_VALUE_REQUESTED_MONITORING); response.put(JSON_KEY_STATUS, JSON_VALUE_OK); response.put(JSON_KEY_EVENT, JSON_VALUE_STARTED); PluginResult result = new PluginResult(PluginResult.Status.OK, response.toString()); result.setKeepCallback(true);//from w w w. j ava 2 s .c o m callbackContext.sendPluginResult(result); }
From source file:com.bourgein.cordova.imageintent.ImageIntent.java
License:Apache License
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { Log.e("JEM", "action: " + action); context = cordova.getActivity().getApplicationContext(); if (action.equals("getExtra")) { Intent intent = ((CordovaActivity) this.cordova.getActivity()).getIntent(); String intentAction = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_SEND.equals(intentAction) && type != null) { if (type.startsWith("image/")) { Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); String destinationFilename = context.getExternalFilesDir(null).getParentFile().getPath() + File.separatorChar + UUID.randomUUID().toString() + ".jpg"; Log.e("JEM", "destinationFilename: " + destinationFilename); if (imageUri != null) { if (copyFileToAppStorage(imageUri, destinationFilename)) { callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, destinationFilename)); return true; } else { return false; }/*from ww w . j av a 2s . c om*/ } else { return false; } } } else if (Intent.ACTION_SEND_MULTIPLE.equals(intentAction) && type != null) { if (type.startsWith("image/")) { ArrayList<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); if (imageUris != null) { ArrayList<String> picList = new ArrayList<String>(); for (Uri uri : imageUris) { String destinationFilename = context.getExternalFilesDir(null).getParentFile().getPath() + File.separatorChar + UUID.randomUUID().toString() + ".jpg"; if (copyFileToAppStorage(uri, destinationFilename)) { picList.add(destinationFilename); } else { return false; } } if (picList.size() > 0) { JSONArray picturesJson = new JSONArray(picList); callbackContext .sendPluginResult(new PluginResult(PluginResult.Status.OK, picturesJson)); return true; } else { return false; } } } } } return false; }
From source file:com.bsafe.sensors.motion.BSMotionSensorsPlugin.java
License:Apache License
/** * Executes the request.//from w w w.j a va 2s.c om * * @param action The action to execute. * @param args The exec() arguments. * @param callbackId The callback id used when calling back into JavaScript. * @return Whether the action was valid. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (action.equals("start")) { this.callbackContext = callbackContext; if (this.status != BSMotionSensorsPlugin.RUNNING) { // If not running, then this is an async call, so don't worry about waiting // We drop the callback onto our stack, call start, and let start and the sensor callback fire off the callback down the road this.start(); } } else if (action.equals("stop")) { if (this.status == BSMotionSensorsPlugin.RUNNING) { this.stop(); } } else { // Unsupported action return false; } PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, ""); result.setKeepCallback(true); callbackContext.sendPluginResult(result); return true; }