Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. package org.apache.cordova.plugin;
  2.  
  3. import org.apache.cordova.CordovaPlugin;
  4. import org.apache.cordova.CallbackContext;
  5.  
  6. import org.json.JSONArray;
  7. import org.json.JSONException;
  8. import org.json.JSONObject;
  9.  
  10. /**
  11. * This class echoes a string called from JavaScript.
  12. */
  13. public class CDVEmarsys extends CordovaPlugin {
  14.  
  15.     @Override
  16.   public void initialize(CordovaInterface cordova, CordovaWebView webView) {
  17.       super.initialize(cordova, webView);
  18.       MobileEngageConfig config = new MobileEngageConfig.Builder()
  19.         .application(this)
  20.         .credentials(<applicationCode: String>, <applicationPassword: String>)
  21.         .statusListener(getStatusListener())
  22.         //either enable or disable the SDK provided Oreo default channel
  23.         //one must be chosen
  24.         //.enableDefaultChannel("default name", "description for the default channel")
  25.         //.disableDefaultChannel()
  26.         .build();
  27.         MobileEngage.setup(config);
  28.   }
  29.  
  30.   @Override
  31.   public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
  32.       if (action.equals("register")) {
  33.           String message = args.getString(0);
  34.           this.register(message, callbackContext);
  35.           return true;
  36.       } else if (action.equals("pushtoken") {
  37.         String message = args.getString(0);
  38.         this.pushToken(message, callbackContext);
  39.         return true;
  40.       }
  41.       return false;
  42.   }
  43.  
  44.   private void register(String message, CallbackContext callbackContext) {
  45.       if (message != null && message.length() > 0) {
  46.           callbackContext.success(message);
  47.       } else {
  48.           callbackContext.error("Expected one non-empty string argument.");
  49.       }
  50.   }
  51.  
  52.   private void pushToken(String message, CallbackContext callbackContext){
  53.     if (message != null && message.length() > 0) {
  54.         callbackContext.success(message);
  55.     } else {
  56.         callbackContext.error("Expected one non-empty string argument.");
  57.     }
  58.   }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement