Java Code Examples for com.getcapacitor.PluginCall#reject()
The following examples show how to use
com.getcapacitor.PluginCall#reject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhoneProviderHandler.java From capacitor-firebase-auth with MIT License | 6 votes |
@Override public void signIn(PluginCall call) { if (!call.getData().has("data")) { call.reject("The auth data is required"); return; } JSObject data = call.getObject("data", new JSObject()); String phone = data.getString("phone", ""); if (phone.equalsIgnoreCase("null") || phone.equalsIgnoreCase("")) { call.reject("The phone number is required"); return; } String code = data.getString("verificationCode", ""); if(code.equalsIgnoreCase("null") || code.equalsIgnoreCase("")) { PhoneAuthProvider.getInstance().verifyPhoneNumber (phone, 60, TimeUnit.SECONDS, this.plugin.getActivity(), this.mCallbacks); } else { AuthCredential credential = PhoneAuthProvider.getCredential(this.mVerificationId, code); this.mVerificationCode = code; plugin.handleAuthCredentials(credential); } }
Example 2
Source File: CapacitorFirebaseAuth.java From capacitor-firebase-auth with MIT License | 6 votes |
@PluginMethod() public void signIn(PluginCall call) { if (!call.getData().has("providerId")) { call.reject("The provider id is required"); return; } ProviderHandler handler = this.getProviderHandler(call); if (handler == null) { Log.w(PLUGIN_TAG, "Provider not supported"); call.reject("The provider is disable or unsupported"); } else { if (handler.isAuthenticated()) { JSObject jsResult = this.build(null, call); call.success(jsResult); } else { this.saveCall(call); handler.signIn(call); } } }
Example 3
Source File: CapacitorFirebaseAuth.java From capacitor-firebase-auth with MIT License | 6 votes |
@Override protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) { Log.d(PLUGIN_TAG, "Handle on Activity Result"); final PluginCall savedCall = getSavedCall(); if (savedCall == null) { Log.d(PLUGIN_TAG, "No saved call on activity result."); return; } final ProviderHandler handler = this.providerHandlerByRC.get(requestCode); if (handler == null) { Log.w(PLUGIN_TAG, "No provider handler with given request code."); savedCall.reject("No provider handler with given request code."); } else { handler.handleOnActivityResult(requestCode, resultCode, data); } }
Example 4
Source File: CapacitorFirebaseAuth.java From capacitor-firebase-auth with MIT License | 6 votes |
public void handleAuthCredentials(AuthCredential credential) { final PluginCall savedCall = getSavedCall(); if (savedCall == null) { Log.d(PLUGIN_TAG, "No saved call on activity result."); return; } if (credential == null) { Log.w(PLUGIN_TAG, "Sign In failure: credentials."); savedCall.reject("Sign In failure: credentials."); return; } if (this.nativeAuth) { nativeAuth(savedCall, credential); } else { JSObject jsResult = this.build(credential, savedCall); savedCall.success(jsResult); } }
Example 5
Source File: Permissions.java From OsmGo with MIT License | 6 votes |
@PluginMethod public void query(PluginCall call) { String name = call.getString("name"); switch (name) { case "camera": checkCamera(call); break; case "photos": checkPhotos(call); break; case "geolocation": checkGeo(call); break; case "notifications": checkNotifications(call); break; case "clipboard-read": case "clipboard-write": checkClipboard(call); break; default: call.reject("Unknown permission type"); } }
Example 6
Source File: CapacitorFirebaseAuth.java From capacitor-firebase-auth with MIT License | 5 votes |
public void handleFailure(String message, Exception e) { PluginCall savedCall = getSavedCall(); if (savedCall == null) { Log.d(PLUGIN_TAG, "No saved call on handle failure."); return; } if (e != null) { savedCall.reject(message, e); } else { savedCall.reject(message); } }
Example 7
Source File: OAuth2ClientPlugin.java From capacitor-oauth2 with MIT License | 5 votes |
void createJsObjAndResolve(PluginCall call, String jsonStr) { try { JSObject json = new JSObject(jsonStr); call.resolve(json); } catch (JSONException e) { call.reject(ERR_GENERAL, e); } }
Example 8
Source File: AdmobPlus.java From admob-plus with MIT License | 5 votes |
@Nullable private Ad getAdOrRejectMissing(PluginCall call) { Integer adId = call.getInt("id"); Ad ad = Ad.getAdById(adId); if (ad == null) { call.reject(String.format("can not find ad for %s", adId)); return null; } return ad; }
Example 9
Source File: Camera.java From OsmGo with MIT License | 5 votes |
public void processPickedImage(PluginCall call, Intent data) { if (data == null) { call.error("No image picked"); return; } Uri u = data.getData(); InputStream imageStream = null; try { imageStream = getActivity().getContentResolver().openInputStream(u); Bitmap bitmap = BitmapFactory.decodeStream(imageStream); if (bitmap == null) { call.reject("Unable to process bitmap"); return; } returnResult(call, bitmap, u); } catch (OutOfMemoryError err) { call.error("Out of memory"); } catch (FileNotFoundException ex) { call.error("No such image found", ex); } finally { if (imageStream != null) { try { imageStream.close(); } catch (IOException e) { Log.e(getLogTag(), UNABLE_TO_PROCESS_IMAGE, e); } } } }
Example 10
Source File: Camera.java From OsmGo with MIT License | 5 votes |
/** * After processing the image, return the final result back to the caller. * @param call * @param bitmap * @param u */ private void returnResult(PluginCall call, Bitmap bitmap, Uri u) { try { bitmap = prepareBitmap(bitmap, u); } catch (IOException e) { call.reject(UNABLE_TO_PROCESS_IMAGE); return; } ExifWrapper exif = ImageUtils.getExifData(getContext(), bitmap, u); // Compress the final image and prepare for output to client ByteArrayOutputStream bitmapOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, settings.getQuality(), bitmapOutputStream); if (settings.isAllowEditing() && !isEdited) { editImage(call, u); return; } if (settings.getResultType() == CameraResultType.BASE64) { returnBase64(call, exif, bitmapOutputStream); } else if (settings.getResultType() == CameraResultType.URI) { returnFileURI(call, exif, bitmap, u, bitmapOutputStream); } else if (settings.getResultType() == CameraResultType.DATAURL) { returnDataUrl(call, exif, bitmapOutputStream); } else { call.reject(INVALID_RESULT_TYPE_ERROR); } // Result returned, clear stored paths imageFileSavePath = null; imageFileUri = null; }
Example 11
Source File: Storage.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void get(PluginCall call) { String key = call.getString("key"); if (key == null) { call.reject("Must provide key"); return; } String value = prefs.getString(key, null); JSObject ret = new JSObject(); ret.put("value", value == null ? JSObject.NULL : value); call.resolve(ret); }
Example 12
Source File: Storage.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void set(PluginCall call) { String key = call.getString("key"); if (key == null) { call.reject("Must provide key"); return; } String value = call.getString("value"); editor.putString(key, value); editor.apply(); call.resolve(); }
Example 13
Source File: Storage.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void remove(PluginCall call) { String key = call.getString("key"); if (key == null) { call.reject("Must provide key"); return; } editor.remove(key); editor.apply(); call.resolve(); }
Example 14
Source File: OAuth2ClientPlugin.java From capacitor-oauth2 with MIT License | 4 votes |
@PluginMethod() public void refreshToken(final PluginCall call) { disposeAuthService(); OAuth2RefreshTokenOptions oAuth2RefreshTokenOptions = buildRefreshTokenOptions(call.getData()); if (oAuth2RefreshTokenOptions.getAppId() == null) { call.reject(ERR_PARAM_NO_APP_ID); return; } if (oAuth2RefreshTokenOptions.getAccessTokenEndpoint() == null) { call.reject(ERR_PARAM_NO_ACCESS_TOKEN_ENDPOINT); return; } if (oAuth2RefreshTokenOptions.getRefreshToken() == null) { call.reject(ERR_PARAM_NO_REFRESH_TOKEN); return; } this.authService = new AuthorizationService(getContext()); AuthorizationServiceConfiguration config = new AuthorizationServiceConfiguration( Uri.parse(""), Uri.parse(oAuth2RefreshTokenOptions.getAccessTokenEndpoint()) ); if (this.authState == null) { this.authState = new AuthState(config); } TokenRequest tokenRequest = new TokenRequest.Builder( config, oAuth2RefreshTokenOptions.getAppId() ).setGrantType(GrantTypeValues.REFRESH_TOKEN) .setScope(oAuth2RefreshTokenOptions.getScope()) .setRefreshToken(oAuth2RefreshTokenOptions.getRefreshToken()) .build(); this.authService.performTokenRequest(tokenRequest, (response1, ex) -> { this.authState.update(response1, ex); if (ex != null) { call.reject(ERR_GENERAL, ex); } else { if (response1 != null) { try { JSObject json = new JSObject(response1.jsonSerializeString()); call.resolve(json); } catch (JSONException e) { call.reject(ERR_GENERAL, e); } } else { call.reject(ERR_NO_ACCESS_TOKEN); } } }); }