List of usage examples for org.apache.cordova PluginResult PluginResult
public PluginResult(Status status, List<PluginResult> multipartMessages)
From source file:com.microsoft.aad.adal.CordovaAdalPlugin.java
License:Open Source License
private boolean readTokenCacheItems(String authority, boolean validateAuthority) throws JSONException { final AuthenticationContext authContext; try {//from w w w . j av a 2 s. co m authContext = getOrCreateContext(authority, validateAuthority); } catch (Exception e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.getMessage())); return true; } JSONArray result = new JSONArray(); ITokenCacheStore cache = authContext.getCache(); if (cache instanceof ITokenStoreQuery) { Iterator<TokenCacheItem> cacheItems = ((ITokenStoreQuery) cache).getAll(); while (cacheItems.hasNext()) { TokenCacheItem item = cacheItems.next(); result.put(tokenItemToJSON(item)); } } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); return true; }
From source file:com.microsoft.aad.adal.CordovaAdalPlugin.java
License:Open Source License
private boolean deleteTokenCacheItem(String authority, boolean validateAuthority, String itemAuthority, String resource, String clientId, String userId, boolean isMultipleResourceRefreshToken) { final AuthenticationContext authContext; try {// w w w . java2 s .c om authContext = getOrCreateContext(authority, validateAuthority); } catch (Exception e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.getMessage())); return true; } String key = CacheKey.createCacheKey(itemAuthority, resource, clientId, isMultipleResourceRefreshToken, userId); authContext.getCache().removeItem(key); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); return true; }
From source file:com.microsoft.aad.adal.CordovaAdalPlugin.java
License:Open Source License
private boolean clearTokenCache(String authority, boolean validateAuthority) { final AuthenticationContext authContext; try {//from www. j av a2 s . co m authContext = getOrCreateContext(authority, validateAuthority); } catch (Exception e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.getMessage())); return true; } authContext.getCache().removeAll(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); return true; }
From source file:com.microsoft.aad.adal.CordovaAdalPlugin.java
License:Open Source License
private boolean setUseBroker(boolean useBroker) { try {/*from ww w. ja v a 2 s . co m*/ AuthenticationSettings.INSTANCE.setUseBroker(useBroker); // Android 6.0 "Marshmallow" introduced a new permissions model where the user can turn on and off permissions as necessary. // This means that applications must handle these permission in run time. // http://cordova.apache.org/docs/en/latest/guide/platforms/android/plugin.html#android-permissions if (useBroker && Build.VERSION.SDK_INT >= 23 /* Build.VERSION_CODES.M */ ) { requestBrokerPermissions(); // Cordova callback will be handled by requestBrokerPermissions method return true; } } catch (Exception e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.getMessage())); return true; } callbackContext.success(); return true; }
From source file:com.microsoft.aad.adal.CordovaAdalPlugin.java
License:Open Source License
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException { for (int r : grantResults) { if (r == PackageManager.PERMISSION_DENIED) { this.callbackContext .sendPluginResult(new PluginResult(PluginResult.Status.ERROR, PERMISSION_DENIED_ERROR)); return; }// w w w. jav a 2 s . co m } callbackContext.success(); }
From source file:com.microsoft.aad.adal.DefaultAuthenticationCallback.java
License:Open Source License
/** * Success callback that serializes AuthenticationResult instance and passes it to Cordova * @param authResult AuthenticationResult instance *///from w ww . jav a 2 s. co m @Override public void onSuccess(AuthenticationResult authResult) { JSONObject result; try { result = authenticationResultToJSON(authResult); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } catch (JSONException e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, "Failed to serialize Authentication result")); } }
From source file:com.microsoft.aad.adal.DefaultAuthenticationCallback.java
License:Open Source License
/** * Error callback that passes error to Cordova * @param authException AuthenticationException *///from ww w .ja v a 2s . c om @Override public void onError(Exception authException) { JSONObject cordovaError = new JSONObject(); try { cordovaError.put("errorDescription", authException.getMessage()); if (authException instanceof AuthenticationException) { cordovaError.put("errorCode", ((AuthenticationException) authException).mCode.toString()); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, cordovaError)); } catch (JSONException ex) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.getMessage())); } }
From source file:com.microsoft.azure.engagement.cordova.AZME.java
License:Open Source License
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (action.equals("enableURL")) { EngagementShared.instance().logD("enableURL=" + lastRedirect); PluginResult result = new PluginResult(PluginResult.Status.OK, lastRedirect); result.setKeepCallback(true);/*from w w w . j a va 2 s. com*/ callbackContext.sendPluginResult(result); onOpenUrlHandlerContext = callbackContext; return true; } else if (action.equals("enableDataPush")) { EngagementShared.instance().logD("enableDataPush"); PluginResult result = new PluginResult(PluginResult.Status.OK); result.setKeepCallback(true); callbackContext.sendPluginResult(result); dataPushHandlerContext = callbackContext; EngagementShared.instance().enableDataPush(); return true; } else if (action.equals("getStatus")) { final CallbackContext cb = callbackContext; EngagementShared.instance().getStatus(new EngagementDelegate() { @Override public void onGetStatusResult(JSONObject _result) { cb.success(_result); } }); return true; } else if (action.equals("startActivity")) { try { String activityName = args.getString(0); String extraInfos = args.getString(1); EngagementShared.instance().startActivity(activityName, extraInfos); callbackContext.success(); } catch (JSONException e) { callbackContext.error("invalid args for startActivity"); } return true; } else if (action.equals("endActivity")) { EngagementShared.instance().endActivity(); callbackContext.success(); return true; } else if (action.equals("sendEvent")) { try { String eventName = args.getString(0); String extraInfos = args.getString(1); EngagementShared.instance().sendEvent(eventName, extraInfos); callbackContext.success(); } catch (JSONException e) { callbackContext.error("invalid args for sendEvent"); } return true; } else if (action.equals("startJob")) { try { String jobName = args.getString(0); String extraInfos = args.getString(1); EngagementShared.instance().startJob(jobName, extraInfos); callbackContext.success(); } catch (JSONException e) { callbackContext.error("invalid args for startJob"); } return true; } else if (action.equals("endJob")) { try { String jobName = args.getString(0); EngagementShared.instance().endJob(jobName); callbackContext.success(); } catch (JSONException e) { callbackContext.error("invalid args for endJob"); } return true; } else if (action.equals("sendSessionEvent")) { try { String eventName = args.getString(0); String extraInfos = args.getString(1); EngagementShared.instance().sendSessionEvent(eventName, extraInfos); callbackContext.success(); } catch (JSONException e) { callbackContext.error("invalid args for sendSessionEvent"); } return true; } else if (action.equals("sendSessionError")) { try { String error = args.getString(0); String extraInfos = args.getString(1); EngagementShared.instance().sendSessionError(error, extraInfos); callbackContext.success(); } catch (JSONException e) { callbackContext.error("invalid args for sendSessionError"); } return true; } else if (action.equals("sendError")) { try { String error = args.getString(0); String extraInfos = args.getString(1); EngagementShared.instance().sendError(error, extraInfos); callbackContext.success(); } catch (JSONException e) { callbackContext.error("invalid args for sendError"); } return true; } else if (action.equals("sendJobEvent")) { try { String eventName = args.getString(0); String jobName = args.getString(1); String extraInfos = args.getString(2); EngagementShared.instance().sendJobEvent(eventName, jobName, extraInfos); callbackContext.success(); } catch (JSONException e) { callbackContext.error("invalid args for sendJobEvent"); } return true; } else if (action.equals("sendJobError")) { try { String error = args.getString(0); String jobName = args.getString(1); String extraInfos = args.getString(2); EngagementShared.instance().sendJobError(error, jobName, extraInfos); callbackContext.success(); } catch (JSONException e) { callbackContext.error("invalid args for sendJobError"); } return true; } else if (action.equals("sendAppInfo")) { try { String extraInfos = args.getString(0); EngagementShared.instance().sendAppInfo(extraInfos); callbackContext.success(); } catch (JSONException e) { callbackContext.error("invalid args for sendAppInfo"); } return true; } else if (action.equals("requestPermissions")) { JSONArray permissions = new JSONArray(); if (realtimeLocation || fineRealtimeLocation) permissions.put("ACCESS_FINE_LOCATION"); else if (lazyAreaLocation) permissions.put("ACCESS_COARSE_LOCATION"); JSONObject ret = EngagementShared.instance().requestPermissions(permissions); if (!ret.has("error")) callbackContext.success(ret); else { String errString = null; try { errString = ret.getString("error"); } catch (JSONException e) { Log.e(EngagementShared.LOG_TAG, "missing error tag"); } callbackContext.error(errString); } return true; } else if (action.equals("setEnabled")) { try { boolean enabled = args.getBoolean(0); EngagementShared.instance().setEnabled(enabled); callbackContext.success(enabled ? 1 : 0); } catch (JSONException e) { callbackContext.error("invalid args for setEnabled"); } return true; } else if (action.equals("isEnabled")) { callbackContext.success(EngagementShared.instance().isEnabled() ? 1 : 0); return true; } String str = "Unrecognized Command : " + action; EngagementShared.instance().logE(str); callbackContext.error(str); return false; }
From source file:com.microsoft.azure.engagement.cordova.AZME.java
License:Open Source License
public void onNewIntent(Intent intent) { super.onNewIntent(intent); String invokeString = intent.getDataString(); if (invokeString != null && !invokeString.equals("")) { EngagementShared.instance().logD("onNewIntent, handleOpenURL " + invokeString); if (onOpenUrlHandlerContext != null) { PluginResult result = new PluginResult(PluginResult.Status.OK, invokeString); result.setKeepCallback(true); onOpenUrlHandlerContext.sendPluginResult(result); } else/*from w ww . j ava 2 s .co m*/ EngagementShared.instance().logD("Cannot trigger onOpenUrl if enableURL not previously called"); } }
From source file:com.microsoft.c3p.cordova.C3PCordovaPlugin.java
License:Open Source License
private static void returnResult(JavaScriptValue result, CallbackContext callbackContext, boolean keepCallback) { PluginResult pluginResult;/*from w ww. java 2 s .c o m*/ switch (result.getType()) { case Null: case String: pluginResult = new PluginResult(PluginResult.Status.OK, result.getString()); break; case Number: // TODO: Fix Cordova to avoid this loss of precision? pluginResult = new PluginResult(PluginResult.Status.OK, (float) result.getDouble()); break; case Boolean: pluginResult = new PluginResult(PluginResult.Status.OK, result.getBoolean()); break; case Object: pluginResult = new PluginResult(PluginResult.Status.OK, (JSONObject) JSValue.toObject(result)); break; case Array: pluginResult = new PluginResult(PluginResult.Status.OK, (JSONArray) JSValue.toObject(result)); break; default: throw new RuntimeException("Result object was not of any expected type."); } if (keepCallback) { pluginResult.setKeepCallback(true); } callbackContext.sendPluginResult(pluginResult); }