List of usage examples for org.apache.cordova PluginResult setKeepCallback
public void setKeepCallback(boolean b)
From source file:org.jboss.aerogear.cordova.push.PushPlugin.java
License:Open Source License
private void register(final CallbackContext callbackContext) { try {//w w w . j ava 2s .c o m PushRegistrar registrar = getPushRegistrar(); registrar.register(getApplicationContext(), new Callback<Void>() { @Override public void onSuccess(Void data) { PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); result.setKeepCallback(true); callbackContext.sendPluginResult(result); success(); } @Override public void onFailure(Exception e) { callbackContext.error(e.getMessage()); } }); } catch (Exception e) { callbackContext.error(e.getMessage()); } }
From source file:org.jboss.aerogear.cordova.push.PushPlugin.java
License:Open Source License
private void success() { PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); pluginResult.setKeepCallback(true); channel.sendPluginResult(pluginResult); }
From source file:org.jboss.aerogear.cordova.push.PushPlugin.java
License:Open Source License
/** * Sends the message to the client application. * If the client application isn't currently active, it is cached for later processing. * @param message the message to be send to the client *//*from w ww. jav a 2 s . co m*/ public static void sendMessage(Bundle message) { if (message != null) { if (sendMetrics && !foreground) { final UnifiedPushMetricsMessage metricsMessage = new UnifiedPushMetricsMessage(message); ((AeroGearFCMPushRegistrar) RegistrarManager.getRegistrar(REGISTRAR)).sendMetrics(metricsMessage, new Callback<UnifiedPushMetricsMessage>() { @Override public void onSuccess(UnifiedPushMetricsMessage unifiedPushMetricsMessage) { Log.i(TAG, String.format("The message '%s' was marked as opened", metricsMessage.getMessageId())); } @Override public void onFailure(Exception e) { Log.e(TAG, e.getMessage(), e); } }); } message.putBoolean("foreground", foreground); if (context != null) { PluginResult result = new PluginResult(PluginResult.Status.OK, convertBundleToJson(message)); result.setKeepCallback(true); context.sendPluginResult(result); } else { Log.v(TAG, "sendMessage: caching message to send at a later time."); cachedMessage = message; } } }
From source file:org.plugin.cordova.deeplink.Deeplink.java
License:Apache License
/** * Create a new plugin result and send it back to JavaScript * * @param deeplink data to set as navigator.deeplink *//*www. j a v a2 s .c om*/ private void sendUpdate(JSONObject data, boolean keepCallback) { if (data != null && this.pluginCallbackContext != null) { PluginResult result = new PluginResult(PluginResult.Status.OK, data); result.setKeepCallback(keepCallback); this.pluginCallbackContext.sendPluginResult(result); } }
From source file:org.pluginporo.barcodescan.BarcodeScanPlugin.java
private void sendUpdate(JSONObject info, boolean keepCallback) { if (this.pluginCallbackContext != null) { PluginResult result = new PluginResult(PluginResult.Status.OK, info); result.setKeepCallback(keepCallback); this.pluginCallbackContext.sendPluginResult(result); }//www . java 2s . co m }
From source file:org.potpie.cordova.plugins.chromecast.ChromecastPlugin.java
License:Open Source License
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("startReceiverListener")) { receiverCallback = callbackContext; PluginResult result = new PluginResult(PluginResult.Status.OK, new JSONObject()); result.setKeepCallback(true); receiverCallback.sendPluginResult(result); return true; } else if (action.equals("setReceiver")) { int index = args.getInt(0); try {/* ww w .j a va 2 s.co m*/ RouteInfo route = routes.get(index); System.out.println("route :" + index + " " + route.getId() + " selected"); mediaRouter.selectRoute(route); callbackContext.success(); return true; } catch (IndexOutOfBoundsException e) { callbackContext.error("Receiver not found"); return false; } } else if (action.equals("cast")) { String mediaurl = args.getString(0); try { System.out.println("cast :" + mediaurl); startCast(mediaurl); callbackContext.success(); return true; } catch (IOException e) { callbackContext.error("cast failed :" + e.getMessage()); return false; } } else if (action.equals("pause")) { try { System.out.println("pause"); pause(); callbackContext.success(); return true; } catch (IOException e) { callbackContext.error("pause failed :" + e.getMessage()); return false; } } else if (action.equals("play")) { try { int position = args.getInt(0); System.out.println("play :" + position); play(position); callbackContext.success(); return true; } catch (IOException e) { callbackContext.error("play failed :" + e.getMessage()); return false; } } else if (action.equals("stopCast")) { try { System.out.println("stopCast"); stopCast(); callbackContext.success(); return true; } catch (IOException e) { callbackContext.error("stop cast failed :" + e.getMessage()); return false; } } else if (action.equals("startStatusListener")) { statusCallback = callbackContext; callbackContext.sendPluginResult(getStatus(null)); return true; } else { callbackContext.error("Invalid action"); return false; } }
From source file:org.potpie.cordova.plugins.chromecast.ChromecastPlugin.java
License:Open Source License
private PluginResult getStatus(String statusMessage) { JSONObject status = new JSONObject(); try {/*from ww w . j a v a 2 s . c om*/ if (messageStream != null) { status.put("state", messageStream.getPlayerState().toString()); status.put("position", messageStream.getStreamPosition()); status.put("duration", messageStream.getStreamDuration()); } else { status.put("state", ""); status.put("position", 0.0); status.put("duration", 0.0); } if (statusMessage != null) { status.put("statusMessage", statusMessage); } } catch (JSONException e) { e.printStackTrace(); } PluginResult result = new PluginResult(PluginResult.Status.OK, status); result.setKeepCallback(true); return result; }
From source file:plugin.google.maps.CordovaGoogleMaps.java
@SuppressWarnings("unused") public void getMyLocation(final JSONArray args, final CallbackContext callbackContext) throws JSONException { // enableHighAccuracy = true -> PRIORITY_HIGH_ACCURACY // enableHighAccuracy = false -> PRIORITY_BALANCED_POWER_ACCURACY JSONObject params = args.getJSONObject(0); boolean isHighLocal = false; if (params.has("enableHighAccuracy")) { isHighLocal = params.getBoolean("enableHighAccuracy"); }// ww w . j ava2 s . com final boolean isHigh = isHighLocal; // Request geolocation permission. boolean locationPermission = cordova.hasPermission("android.permission.ACCESS_COARSE_LOCATION"); if (!locationPermission) { //_saveArgs = args; //_saveCallbackContext = callbackContext; synchronized (semaphore) { cordova.requestPermissions(this, callbackContext.hashCode(), new String[] { "android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION" }); try { semaphore.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } locationPermission = cordova.hasPermission("android.permission.ACCESS_COARSE_LOCATION"); if (!locationPermission) { callbackContext.error("Geolocation permission request was denied."); return; } } if (googleApiClient == null) { googleApiClient = new GoogleApiClient.Builder(activity).addApi(LocationServices.API) .addConnectionCallbacks( new com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle connectionHint) { Log.e(TAG, "===> onConnected"); CordovaGoogleMaps.this.sendNoResult(callbackContext); _checkLocationSettings(isHigh, callbackContext); } @Override public void onConnectionSuspended(int cause) { Log.e(TAG, "===> onConnectionSuspended"); } }) .addOnConnectionFailedListener( new com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(@NonNull ConnectionResult result) { Log.e(TAG, "===> onConnectionFailed"); PluginResult tmpResult = new PluginResult(PluginResult.Status.ERROR, result.toString()); tmpResult.setKeepCallback(false); callbackContext.sendPluginResult(tmpResult); googleApiClient.disconnect(); } }) .build(); googleApiClient.connect(); } else if (googleApiClient.isConnected()) { _checkLocationSettings(isHigh, callbackContext); } }
From source file:plugin.google.maps.CordovaGoogleMaps.java
protected void sendNoResult(CallbackContext callbackContext) { PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); }
From source file:plugin.google.maps.GoogleMaps.java
@SuppressWarnings("unused") private void getMyLocation(final JSONArray args, final CallbackContext callbackContext) throws JSONException { // enableHighAccuracy = true -> PRIORITY_HIGH_ACCURACY // enableHighAccuracy = false -> PRIORITY_BALANCED_POWER_ACCURACY JSONObject params = args.getJSONObject(0); boolean isHigh = false; if (params.has("enableHighAccuracy")) { isHigh = params.getBoolean("enableHighAccuracy"); }// w ww . jav a 2 s . c om final boolean enableHighAccuracy = isHigh; if (googleApiClient == null) { googleApiClient = new GoogleApiClient.Builder(this.activity).addApi(LocationServices.API) .addConnectionCallbacks( new com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle connectionHint) { Log.e("CordovaLog", "===> onConnected"); GoogleMaps.this.sendNoResult(callbackContext); _checkLocationSettings(enableHighAccuracy, callbackContext); } @Override public void onConnectionSuspended(int cause) { Log.e("CordovaLog", "===> onConnectionSuspended"); } }) .addOnConnectionFailedListener( new com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(ConnectionResult result) { Log.e("CordovaLog", "===> onConnectionFailed"); PluginResult tmpResult = new PluginResult(PluginResult.Status.ERROR, result.toString()); tmpResult.setKeepCallback(false); callbackContext.sendPluginResult(tmpResult); googleApiClient.disconnect(); } }) .build(); googleApiClient.connect(); } else if (googleApiClient.isConnected()) { _checkLocationSettings(enableHighAccuracy, callbackContext); } }