private void javascriptCallback(String event, JSONObject arguments, CallbackContext callbackContext) { if (callbackContext == null) { return; } JSONObject options = new JSONObject(); try { options.putOpt("callback", event); options.putOpt("arguments", arguments); } catch (JSONException e) { callbackContext.sendPluginResult(new PluginResult( PluginResult.Status.JSON_EXCEPTION)); return; } PluginResult result = new PluginResult(Status.OK, options); result.setKeepCallback(true); callbackContext.sendPluginResult(result); }
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException { for(int r:grantResults) { if(r == PackageManager.PERMISSION_DENIED) { mInitCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "Permission denied")); return; } } switch(requestCode) { case RECORD_AUDIO_REQ_CODE: startGCMRegistration(); break; } }
@Override public void execute(String rawArgs, CallbackContext ctx) { try { String args = new JSONArray(rawArgs).getString(0); Connection conn = _map.get(Integer.parseInt(args.substring(0, 8), 16)); if (conn != null) { if (args.charAt(8) == '1') { byte[] binary = Base64.decode(args.substring(args.indexOf(',') + 1), Base64.NO_WRAP); conn.sendMessage(binary, 0, binary.length); } else { conn.sendMessage(args.substring(9)); } } else { } } catch (Exception e) { if (!ctx.isFinished()) { PluginResult result = new PluginResult(Status.ERROR); result.setKeepCallback(true); ctx.sendPluginResult(result); } } }
@Override public void execute(String rawArgs, CallbackContext ctx) { try { JSONArray args = new JSONArray(rawArgs); int id = Integer.parseInt(args.getString(0), 16); int code = args.getInt(1); String reason = args.getString(2); Connection conn = _map.get(id); if (conn != null) { if (code > 0) { conn.close(code, reason); } else { conn.close(); } } } catch (Exception e) { if (!ctx.isFinished()) { PluginResult result = new PluginResult(Status.ERROR); result.setKeepCallback(true); ctx.sendPluginResult(result); } } }
private PluginResult sendSMS(String Phone, String messages,String methods,CallbackContext callbackContext) { String phoneNumber = Phone; String message = messages; String method = methods; SmsSender smsSender=new SmsSender(this.cordova.getActivity()); if(method.equalsIgnoreCase("INTENT")){ smsSender.invokeSMSIntent(phoneNumber,message); callbackContext.sendPluginResult(new PluginResult( PluginResult.Status.NO_RESULT)); } else{ smsSender.sendSMS(phoneNumber,message); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); // TODO Auto-generated method stub return null; }
private void getHardwareInfo(JSONArray args, final CallbackContext callbackContext) { String uuid = Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); JSONObject j = new JSONObject(); try { j.put("uuid", uuid); j.put("platform", this.getPlatform()); j.put("tz", this.getTimeZoneID()); j.put("tz_offset", this.getTimeZoneOffset()); j.put("os_version", this.getOSVersion()); j.put("sdk_version", this.getSDKVersion()); } catch(JSONException ex) {} final PluginResult result = new PluginResult(PluginResult.Status.OK, j); callbackContext.sendPluginResult(result); }
public void sendCallback(String action, ServiceInfo service) { CallbackContext callbackContext = callbacks.get(service.getType()); if (callbackContext == null) { return; } JSONObject status = new JSONObject(); try { status.put("action", action); status.put("service", jsonifyService(service)); Log.d(TAG, "Sending result: " + status.toString()); PluginResult result = new PluginResult(PluginResult.Status.OK, status); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } catch (JSONException e) { Log.e(TAG, e.getMessage(), e); callbackContext.error("Error: " + e.getMessage()); } }
public void onFetchCompleted() { Log.d(LOG_TAG, String.format("%s", "onFetchCompleted")); PluginResult pr = new PluginResult(PluginResult.Status.OK, "onVideoAdLoaded"); pr.setKeepCallback(true); callbackContextKeepCallback.sendPluginResult(pr); //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); //callbackContextKeepCallback.sendPluginResult(pr); pr = new PluginResult(PluginResult.Status.OK, "onRewardedVideoAdLoaded"); pr.setKeepCallback(true); callbackContextKeepCallback.sendPluginResult(pr); //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); //callbackContextKeepCallback.sendPluginResult(pr); }
public void onVideoCompleted(String itemKey, boolean skipped) { Log.d(LOG_TAG, String.format("%s", "onVideoCompleted")); if (!skipped) { if (videoOrRewardedVideo == 1) { } else if (videoOrRewardedVideo == 2) { PluginResult pr = new PluginResult(PluginResult.Status.OK, "onRewardedVideoAdCompleted"); pr.setKeepCallback(true); callbackContextKeepCallback.sendPluginResult(pr); //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); //callbackContextKeepCallback.sendPluginResult(pr); } } }
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { PluginResult result = null; if (ACTION_GET_SSID.equals(action)) { result = executeGetWifiInfo(args, callbackContext); } else if (ACTION_START_CONFIG.equals(action)) { result = executeStartConfig(args, callbackContext); } else if (ACTION_STOP_CONFIG.equals(action)) { result = executeStopConfig(args, callbackContext); } else if (ACTION_START_FIND_DEVICE.equals(action)) { result = executeStartFindDevice(args, callbackContext); } else if (ACTION_STOP_FIND_DEVICE.equals(action)) { result = executeStopFindDevice(args, callbackContext); } else { Log.d(LOG_TAG, String.format("Invalid action passed: %s", action)); result = new PluginResult(Status.INVALID_ACTION); } if(result != null) callbackContext.sendPluginResult( result ); return true; }
public void initialize(CordovaArgs args, final CallbackContext ctx) throws JSONException { service.addPurchaseObserver(this); service.init(new InAppService.InitCompletion() { @Override public void onInit(Error error) { JSONObject data = new JSONObject(); try { data.put("products", InAppServicePlugin.this.productsToJSON(service.getProducts())); data.put("canPurchase", service.canPurchase()); if (error != null) { data.put("error", errorToJSON(error)); } } catch (JSONException e) { e.printStackTrace(); } ctx.sendPluginResult(new PluginResult(Status.OK, data)); } }); }
public void fetchProducts(CordovaArgs args, final CallbackContext ctx) { JSONArray array = args.optJSONArray(0); if (array == null) { ctx.sendPluginResult(new PluginResult(Status.INVALID_ACTION, "Invalid argument")); return; } ArrayList<String> productIds = new ArrayList<String>(); for (int i = 0; i < array.length(); ++i) { productIds.add(array.optString(i, "empty")); } service.fetchProducts(productIds, new InAppService.FetchCallback() { @Override public void onComplete(final List<InAppProduct> products, Error error) { if (error != null) { ctx.sendPluginResult(new PluginResult(Status.ERROR, errorToJSON(error))); } else { ctx.sendPluginResult(new PluginResult(Status.OK, productsToJSON(products))); } } }); }
public void consume(CordovaArgs args, final CallbackContext ctx) { String productId = args.optString(0); if (productId == null) { ctx.sendPluginResult(new PluginResult(Status.ERROR, "Invalid argument")); return; } int quantity = args.optInt(1); if (quantity < 1) { quantity = 1; } service.consume(productId, quantity, new InAppService.ConsumeCallback() { @Override public void onComplete(int consumed, Error error) { if (error != null) { ctx.sendPluginResult(new PluginResult(Status.ERROR, errorToJSON(error))); } else { ctx.sendPluginResult(new PluginResult(Status.OK, consumed)); } } }); }
public void setValidationHandler(CordovaArgs args, final CallbackContext ctx) { boolean noValidation = args.optBoolean(0); if (noValidation) { service.setValidationHandler(null); return; } service.setValidationHandler(new InAppService.ValidationHandler() { @Override public void onValidate(String receipt, String productId, ValidationCompletion completion) { int completionId = validationIndex++; validationCompletions.put(completionId, completion); JSONArray array = new JSONArray(); array.put(receipt); array.put(productId); array.put(completionId); PluginResult result = new PluginResult(Status.OK, array); result.setKeepCallback(true); ctx.sendPluginResult(result); } }); }
/** * This is the main method for the MIFARE Plugin. All API calls go through * here. This method determines the action, and executes the appropriate * call. * * @param action The action that the plugin should execute. * @param args The input parameters for the action. * @param callbackContext The callback context. * @return A PluginResult representing the result of the provided action. A * status of INVALID_ACTION is returned if the action is not * recognized. */ @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult result; NxpLogUtils.enableLog(); NxpLogUtils.i(LOGTAG, "MIFARE Cordova plugin execute"); if (ACTION_INIT.equals(action)) { result = init(args.getJSONObject(0), callbackContext); } else if (ACTION_WRITE_TAG_DATA.equals(action)) { result = writeTag(args.getJSONObject(0), callbackContext); } else { result = new PluginResult(Status.INVALID_ACTION); } if (result != null) { callbackContext.sendPluginResult(result); } return true; }
private PluginResult executeEnableWifi(JSONArray inputs, CallbackContext callbackContext) { Log.w(LOGTAG, "executeEnableWifi"); Context context = cordova.getActivity().getApplicationContext(); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); boolean toEnable = true; try { toEnable = inputs.getBoolean( 0 ); } catch (JSONException e) { Log.w(LOGTAG, String.format("Got JSON Exception: %s", e.getMessage())); return new PluginResult(Status.JSON_EXCEPTION); } wifiManager.setWifiEnabled( toEnable ); callbackContext.success(); return null; }
private boolean executeGetStatus(JSONArray inputs, CallbackContext callbackContext) { String status = "0"; PayPal pp = PayPal.getInstance(); Log.i("mpl", "getStatus: after instance"); if( (pp != null) && pp.isLibraryInitialized() ) { status = "1"; } JSONObject json = new JSONObject(); try { json.put("str", status); } catch (JSONException e) { } callbackContext.sendPluginResult( new PluginResult(Status.OK, json) ); return true; }
public void onPaymentSucceeded(final String payKey, final String paymentStatus) { Log.i(LOGTAG, "onPaymentSucceeded"); cordova.getActivity().runOnUiThread(new Runnable() { public void run() { PayPalMPL.thisPlugin.webView.loadUrl("javascript:" + "(function() {" + "var e = document.createEvent('Events');" + "e.initEvent('PaypalPaymentEvent.Success');" + "e.payKey = '"+ payKey + "';" + "e.paymentStatus = '"+ paymentStatus + "';" + "document.dispatchEvent(e);" + "})();"); } }); this.payCallback.sendPluginResult( new PluginResult(Status.OK, paymentStatus) ); }
public void onPaymentFailed(final String paymentStatus, final String correlationID, final String payKey, final String errorID, final String errorMessage) { Log.i(LOGTAG, "onPaymentFailed"); cordova.getActivity().runOnUiThread(new Runnable() { public void run() { PayPalMPL.thisPlugin.webView.loadUrl( "javascript:" + "(function() {" + "var e = document.createEvent('Events');" + "e.initEvent('PaypalPaymentEvent.Failed');" + "e.payKey = '" + payKey + "';" + "e.paymentStatus = '" + paymentStatus + "';" + "e.correlationID = '" + correlationID + "';" + "e.errorID = '" + errorID + "';" + "e.errorMessage = '" + errorMessage + "';" + "document.dispatchEvent(e);" + "})();" ); } }); this.payCallback.sendPluginResult(new PluginResult(Status.ERROR, errorMessage)); }
public void onPaymentCanceled(final String paymentStatus) { Log.i(LOGTAG, "onPaymentCanceled"); cordova.getActivity().runOnUiThread(new Runnable() { public void run() { PayPalMPL.thisPlugin.webView.loadUrl( "javascript:" + "(function() {" + "var e = document.createEvent('Events');" + "e.initEvent('PaypalPaymentEvent.Canceled');" + "e.paymentStatus = '"+ paymentStatus + "';" + "document.dispatchEvent(e);" + "})();"); } }); this.payCallback.sendPluginResult(new PluginResult(Status.ERROR, paymentStatus)); }
/** * This is the main method for the Amazon Ads plugin. All API calls go * through here. This method determines the action, and executes the * appropriate call. * * @param action * The action that the plugin should execute. * @param inputs * The input parameters for the action. * @param callbackContext * The callback context. * @return A PluginResult representing the result of the provided action. A * status of INVALID_ACTION is returned if the action is not * recognized. */ @Override public boolean execute(String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException { PluginResult result = null; if (ACTION_CREATE_INTERSTITIAL_AD.equals(action)) { JSONObject options = inputs.optJSONObject(0); result = executeCreateInterstitialAd(options, callbackContext); } else if (ACTION_SHOW_INTERSTITIAL_AD.equals(action)) { result = executeShowInterstitialAd(callbackContext); } else { result = new PluginResult(Status.INVALID_ACTION); } if (result != null) callbackContext.sendPluginResult(result); return true; }
private PluginResult executeShowInterstitialAd(final CallbackContext callbackContext) { if (interstitialAd == null) { return new PluginResult(Status.ERROR, "Interstitial Ad not available, call createInterstitialAd first."); } cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (interstitialAd.showAd()) { if (callbackContext != null) { callbackContext.success(); } } else { if (callbackContext != null) { callbackContext.error("Ad not showed"); } } } }); return null; }
public void tryConnect (CallbackContext callbackContext) { boolean isGpsAvailable = (GooglePlayServicesUtil.isGooglePlayServicesAvailable(cordova.getActivity()) == ConnectionResult.SUCCESS); if (!isGpsAvailable) { callbackContext.sendPluginResult (new PluginResult (PluginResult.Status.OK, false)); return; } tryConnectCallback = callbackContext; mGoogleApiClient = new GoogleApiClient.Builder (cordova.getActivity().getApplicationContext()) .addConnectionCallbacks (this) .addOnConnectionFailedListener (this) .addApi (Games.API) .addScope (Games.SCOPE_GAMES) .addApi(Plus.API) .addScope(Plus.SCOPE_PLUS_PROFILE) .addScope(Plus.SCOPE_PLUS_LOGIN) .build (); mGoogleApiClient.connect (); }
/** * This is the main method for the AdMob plugin. All API calls go through here. * This method determines the action, and executes the appropriate call. * * @param action The action that the plugin should execute. * @param inputs The input parameters for the action. * @param callbackId The callback ID. This is currently unused. * @return A PluginResult representing the result of the provided action. A * status of INVALID_ACTION is returned if the action is not recognized. */ @Override public boolean execute(String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException { PluginResult result = null; if (ACTION_CREATE_BANNER_VIEW.equals(action)) { result = executeCreateBannerView(inputs); } else if (ACTION_DESTROY_BANNER_VIEW.equals(action)) { result = executeDestroyBannerView(inputs); } else if (ACTION_REQUEST_AD.equals(action)) { result = executeRequestAd(inputs); } else if (ACTION_SHOW_AD.equals(action)) { result = executeShowAd(inputs); } else { Log.d(LOGTAG, String.format("Invalid action passed: %s", action)); result = new PluginResult(Status.INVALID_ACTION); } callbackContext.sendPluginResult( result ); return true; }
/** * Parses the create banner view input parameters and runs the create banner * view action on the UI thread. If this request is successful, the developer * should make the requestAd call to request an ad for the banner. * * @param inputs The JSONArray representing input parameters. This function * expects the first object in the array to be a JSONObject with the * input parameters. * @return A PluginResult representing whether or not the banner was created * successfully. */ private PluginResult executeCreateBannerView(JSONArray inputs) { String publisherId; String size; // Get the input data. try { publisherId = inputs.getString( PUBLISHER_ID_ARG_INDEX ); size = inputs.getString( AD_SIZE_ARG_INDEX ); this.bannerAtTop = inputs.getBoolean( POSITION_AT_TOP_ARG_INDEX ); } catch (JSONException exception) { Log.w(LOGTAG, String.format("Got JSON Exception: %s", exception.getMessage())); return new PluginResult(Status.JSON_EXCEPTION); } // Create the AdView on the UI thread. return executeRunnable(new CreateBannerViewRunnable( publisherId, adSizeFromSize(size))); }
/** * Parses the request ad input parameters and runs the request ad action on * the UI thread. * * @param inputs The JSONArray representing input parameters. This function * expects the first object in the array to be a JSONObject with the * input parameters. * @return A PluginResult representing whether or not an ad was requested * succcessfully. Listen for onReceiveAd() and onFailedToReceiveAd() * callbacks to see if an ad was successfully retrieved. */ private PluginResult executeRequestAd(JSONArray inputs) { boolean isTesting; JSONObject inputExtras; // Get the input data. try { isTesting = inputs.getBoolean( IS_TESTING_ARG_INDEX ); inputExtras = inputs.getJSONObject( EXTRAS_ARG_INDEX ); } catch (JSONException exception) { Log.w(LOGTAG, String.format("Got JSON Exception: %s", exception.getMessage())); return new PluginResult(Status.JSON_EXCEPTION); } // Request an ad on the UI thread. return executeRunnable(new RequestAdRunnable(isTesting, inputExtras)); }
@Override public void run() { if (adSize == null) { result = new PluginResult(Status.ERROR, "AdSize is null. Did you use an AdSize constant?"); } else { adView = new AdView(cordova.getActivity(), adSize, publisherId); adView.setAdListener(new BannerListener()); LinearLayoutSoftKeyboardDetect parentView = (LinearLayoutSoftKeyboardDetect) webView.getParent(); if (bannerAtTop) { parentView.addView(adView, 0); } else { parentView.addView(adView); } // Notify the plugin. result = new PluginResult(Status.OK); } synchronized (this) { this.notify(); } }
@SuppressWarnings("unchecked") @Override public void run() { if (adView == null) { result = new PluginResult(Status.ERROR, "AdView is null. Did you call createBannerView?"); } else { if (this.show) { adView.setVisibility(View.VISIBLE); } else { adView.setVisibility(View.GONE); } } synchronized (this) { this.notify(); } }
private PluginResult addAlarm(Context context, String what, Date when, ShowOption showOption, JSONObject extras){ PluginResult result = null; // Create an alarm record Alarm alarm = new Alarm(); alarm.setClassName(what); alarm.setWhen(when); alarm.setShowOption(showOption); alarm.setExtras(extras); // Now save the alarm SchedulerDAL dal = new SchedulerDAL(context); int id = dal.add(alarm); if (id > 0) { dal.save(); addToAlarmManager(context, alarm); result = new PluginResult(Status.OK, dal.getAsJSON(id)); } else { result = new PluginResult(Status.ERROR, "Unable to save Alarm details"); } return result; }
private PluginResult cancelAlarm(Context context, int id) { PluginResult result = null; Alarm alarm = new Alarm(); alarm.setId(id); SchedulerDAL dal = new SchedulerDAL(context); dal.delete(alarm); dal.save(); dal = null; cancelFromAlarmManager(context, alarm); result = new PluginResult(Status.OK); return result; }
private PluginResult updateAlarm(Context context, int id, String what, Date when, ShowOption showOption, JSONObject extras) { PluginResult result = null; Alarm alarm = new Alarm(); alarm.setId(id); alarm.setClassName(what); alarm.setWhen(when); alarm.setShowOption(showOption); alarm.setExtras(extras); SchedulerDAL dal = new SchedulerDAL(context); dal.update(alarm); dal.save(); cancelFromAlarmManager(context, alarm); addToAlarmManager(context, alarm); result = new PluginResult(Status.OK, dal.getAsJSON(id)); return result; }