Java Code Examples for com.getcapacitor.PluginCall#error()
The following examples show how to use
com.getcapacitor.PluginCall#error() .
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: Camera.java From OsmGo with MIT License | 7 votes |
private void editImage(PluginCall call, Uri uri) { try { Uri origPhotoUri = uri; if (imageFileUri != null) { origPhotoUri = imageFileUri; } Intent editIntent = new Intent(Intent.ACTION_EDIT); editIntent.setDataAndType(origPhotoUri, "image/*"); File editedFile = CameraUtils.createImageFile(getActivity(), false); Uri editedUri = Uri.fromFile(editedFile); editIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); editIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); editIntent.putExtra(MediaStore.EXTRA_OUTPUT, editedUri); startActivityForResult(call, editIntent, REQUEST_IMAGE_EDIT); } catch (Exception ex) { call.error(IMAGE_EDIT_ERROR, ex); } }
Example 2
Source File: StatusBar.java From OsmGo with MIT License | 6 votes |
@PluginMethod() public void setStyle(final PluginCall call) { final String style = call.getString("style"); if (style == null) { call.error("Style must be provided"); return; } getBridge().executeOnMainThread(new Runnable() { @Override public void run() { Window window = getActivity().getWindow(); View decorView = window.getDecorView(); int visibilityFlags = decorView.getSystemUiVisibility(); if (style.equals("DARK")) { decorView.setSystemUiVisibility(visibilityFlags & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); } else { decorView.setSystemUiVisibility(visibilityFlags | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); } call.success(); } }); }
Example 3
Source File: AdMob.java From capacitor-admob with MIT License | 6 votes |
@PluginMethod() public void hideBanner(PluginCall call) { try { getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (mAdViewLayout != null) { mAdViewLayout.setVisibility(View.GONE); mAdView.pause(); } } }); call.success(new JSObject().put("value", true)); }catch (Exception ex) { call.error(ex.getLocalizedMessage(), ex); } }
Example 4
Source File: AdMob.java From capacitor-admob with MIT License | 6 votes |
@PluginMethod() public void resumeBanner(PluginCall call) { try { getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (mAdViewLayout != null && mAdView != null) { mAdViewLayout.setVisibility(View.VISIBLE); mAdView.resume(); Log.d(getLogTag(), "Banner AD Resumed"); } } }); call.success(new JSObject().put("value", true)); }catch (Exception ex) { call.error(ex.getLocalizedMessage(), ex); } }
Example 5
Source File: AdMob.java From capacitor-admob with MIT License | 6 votes |
@PluginMethod() public void removeBanner(PluginCall call) { try { if (mAdView != null) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (mAdView != null) { mViewGroup.removeView(mAdViewLayout); mAdViewLayout.removeView(mAdView); mAdView.destroy(); mAdView = null; Log.d(getLogTag(), "Banner AD Removed"); } } }); } call.success(new JSObject().put("value", true)); }catch (Exception ex) { call.error(ex.getLocalizedMessage(), ex); } }
Example 6
Source File: Toast.java From OsmGo with MIT License | 6 votes |
@PluginMethod() public void show(PluginCall call) { CharSequence text = call.getString("text"); if(text == null) { call.error("Must provide text"); return; } String durationType = call.getString("durationType", "short"); int duration = android.widget.Toast.LENGTH_SHORT; if("long".equals(durationType)) { duration = android.widget.Toast.LENGTH_LONG; } android.widget.Toast toast = android.widget.Toast.makeText(getContext(), text, duration); toast.show(); call.success(); }
Example 7
Source File: Haptics.java From OsmGo with MIT License | 6 votes |
@PluginMethod() @SuppressWarnings("MissingPermission") public void vibrate(PluginCall call) { Context c = this.getContext(); int duration = call.getInt("duration", 300); if(!hasPermission(Manifest.permission.VIBRATE)) { call.error("Can't vibrate: Missing VIBRATE permission in AndroidManifest.xml"); return; } if (Build.VERSION.SDK_INT >= 26) { ((Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(duration, VibrationEffect.DEFAULT_AMPLITUDE)); } else { vibratePre26(duration); } call.success(); }
Example 8
Source File: AdMob.java From capacitor-admob with MIT License | 6 votes |
@PluginMethod() public void showRewardVideoAd(final PluginCall call) { try { getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (mRewardedVideoAd != null && mRewardedVideoAd.isLoaded()) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { mRewardedVideoAd.show(); } }); call.success(new JSObject().put("value", true)); }else { call.error("The RewardedVideoAd wasn't loaded yet."); } } }); }catch (Exception ex) { call.error(ex.getLocalizedMessage(), ex); } }
Example 9
Source File: Modals.java From OsmGo with MIT License | 6 votes |
@PluginMethod() public void alert(final PluginCall call) { final Activity c = this.getActivity(); final String title = call.getString("title"); final String message = call.getString("message"); final String buttonTitle = call.getString("buttonTitle", "OK"); if(title == null || message == null) { call.error("Please provide a title or message for the alert"); return; } if (c.isFinishing()) { call.error("App is finishing"); return; } Dialogs.alert(c, message, title, buttonTitle, new Dialogs.OnResultListener() { @Override public void onResult(boolean value, boolean didCancel, String inputValue) { call.success(); } }); }
Example 10
Source File: FCMPlugin.java From capacitor-fcm with MIT License | 6 votes |
@PluginMethod() public void deleteInstance(final PluginCall call) { Runnable r = () -> { try { FirebaseInstanceId.getInstance().deleteInstanceId(); call.success(); } catch (IOException e) { e.printStackTrace(); call.error("Cant delete Firebase Instance ID", e); } }; // Run in background thread since `deleteInstanceId()` is a blocking request. // See https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId#deleteInstanceId() new Thread(r).start(); }
Example 11
Source File: Filesystem.java From OsmGo with MIT License | 6 votes |
@PluginMethod() public void stat(PluginCall call) { saveCall(call); String path = call.getString("path"); String directory = getDirectoryParameter(call); File fileObject = getFileObject(path, directory); if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_STAT_PERMISSIONS, Manifest.permission.READ_EXTERNAL_STORAGE)) { if (!fileObject.exists()) { call.error("File does not exist"); return; } JSObject data = new JSObject(); data.put("type", fileObject.isDirectory() ? "directory" : "file"); data.put("size", fileObject.length()); data.put("ctime", null); data.put("mtime", fileObject.lastModified()); data.put("uri", Uri.fromFile(fileObject).toString()); call.success(data); } }
Example 12
Source File: Browser.java From OsmGo with MIT License | 6 votes |
@PluginMethod() public void prefetch(PluginCall call) { JSArray urls = call.getArray("urls"); if (urls == null || urls.length() == 0) { call.error("Must provide an array of URLs to prefetch"); return; } CustomTabsSession session = getCustomTabsSession(); if (session == null) { call.error("Browser session isn't ready yet"); return; } try { for (String url : urls.<String>toList()) { session.mayLaunchUrl(Uri.parse(url), null, null); } } catch(JSONException ex) { call.error("Unable to process provided urls list. Ensure each item is a string and valid URL", ex); return; } }
Example 13
Source File: Accessibility.java From OsmGo with MIT License | 6 votes |
@PluginMethod() public void speak(PluginCall call) { final String value = call.getString("value"); final String language = call.getString("language", "en"); final Locale locale = Locale.forLanguageTag(language); if (locale == null) { call.error("Language was not a valid language tag."); return; } tts = new TextToSpeech(getContext(), new TextToSpeech.OnInitListener() { @Override public void onInit(int i) { tts.setLanguage(locale); tts.speak(value, TextToSpeech.QUEUE_FLUSH, null, "capacitoraccessibility" + System.currentTimeMillis()); } }); // Not yet implemented throw new UnsupportedOperationException(); }
Example 14
Source File: Camera.java From OsmGo with MIT License | 5 votes |
private void showCamera(final PluginCall call) { if (!getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) { call.error(NO_CAMERA_ERROR); return; } openCamera(call); }
Example 15
Source File: BackgroundTask.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void finish(PluginCall call) { String taskId = call.getString("taskId"); if (taskId == null) { call.error("Must provide taskId"); return; } call.success(); }
Example 16
Source File: Modals.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void showActions(final PluginCall call) { String title = call.getString("title"); String message = call.getString("message", ""); JSArray options = call.getArray("options"); if (title == null) { call.error("Must supply a title"); return; } if (options == null) { call.error("Must supply options"); return; } if (getActivity().isFinishing()) { call.error("App is finishing"); return; } final ModalsBottomSheetDialogFragment fragment = new ModalsBottomSheetDialogFragment(); fragment.setOptions(options); fragment.setOnSelectedListener(new ModalsBottomSheetDialogFragment.OnSelectedListener() { @Override public void onSelected(int index) { JSObject ret = new JSObject(); ret.put("index", index); call.success(ret); fragment.dismiss(); } }); fragment.show(getActivity().getSupportFragmentManager(), "capacitorModalsActionSheet"); }
Example 17
Source File: AdMob.java From capacitor-admob with MIT License | 5 votes |
@PluginMethod() public void stopRewardedVideo(PluginCall call) { try { getActivity().runOnUiThread(new Runnable() { @Override public void run() { mRewardedVideoAd.destroy(getContext()); } }); call.success(new JSObject().put("value", true)); }catch (Exception ex) { call.error(ex.getLocalizedMessage(), ex); } }
Example 18
Source File: App.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void openUrl(PluginCall call) { String url = call.getString("url"); if (url == null) { call.error("Must provide a url to open"); return; } JSObject ret = new JSObject(); final PackageManager manager = getContext().getPackageManager(); Intent launchIntent = new Intent(Intent.ACTION_VIEW); launchIntent.setData(Uri.parse(url)); try { getActivity().startActivity(launchIntent); ret.put("completed", true); } catch(Exception ex) { launchIntent = manager.getLaunchIntentForPackage(url); try { getActivity().startActivity(launchIntent); ret.put("completed", true); } catch(Exception expgk) { ret.put("completed", false); } } call.success(ret); }
Example 19
Source File: AdMob.java From capacitor-admob with MIT License | 4 votes |
@PluginMethod() public void prepareRewardVideoAd(final PluginCall call) { this.call = call; /* dedicated test ad unit ID for Android rewarded video: ca-app-pub-3940256099942544/5224354917 */ final String adId = call.getString("adId", "ca-app-pub-3940256099942544/5224354917"); try { mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(getContext()); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mRewardedVideoAd.loadAd(adId, new AdRequest.Builder().build()); mRewardedVideoAd.setRewardedVideoAdListener(new RewardedVideoAdListener() { @Override public void onRewardedVideoAdLoaded() { call.success(new JSObject().put("value", true)); notifyListeners("onRewardedVideoAdLoaded", new JSObject().put("value", true)); } @Override public void onRewardedVideoAdOpened() { notifyListeners("onRewardedVideoAdOpened", new JSObject().put("value", true)); } @Override public void onRewardedVideoStarted() { notifyListeners("onRewardedVideoStarted", new JSObject().put("value", true)); } @Override public void onRewardedVideoAdClosed() { notifyListeners("onRewardedVideoAdClosed", new JSObject().put("value", true)); } @Override public void onRewarded(RewardItem rewardItem) { notifyListeners("onRewarded", new JSObject().put("value", true)); } @Override public void onRewardedVideoAdLeftApplication() { notifyListeners("onRewardedVideoAdLeftApplication", new JSObject().put("value", true)); } @Override public void onRewardedVideoAdFailedToLoad(int i) { notifyListeners("onRewardedVideoAdFailedToLoad", new JSObject().put("value", true)); } @Override public void onRewardedVideoCompleted() { notifyListeners("onRewardedVideoCompleted", new JSObject().put("value", true)); } }); } }); }catch (Exception ex) { call.error(ex.getLocalizedMessage(), ex); } }
Example 20
Source File: AdMob.java From capacitor-admob with MIT License | 4 votes |
@PluginMethod() public void prepareInterstitial(final PluginCall call) { this.call = call; /* dedicated test ad unit ID for Android interstitials: ca-app-pub-3940256099942544/1033173712 */ String adId = call.getString("adId", "ca-app-pub-3940256099942544/1033173712"); try { mInterstitialAd = new InterstitialAd(getContext()); mInterstitialAd.setAdUnitId(adId); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mInterstitialAd.loadAd(new AdRequest.Builder().build()); mInterstitialAd.setAdListener(new AdListener() { @Override public void onAdLoaded() { // Code to be executed when an ad finishes loading. notifyListeners("onAdLoaded", new JSObject().put("value", true)); call.success(new JSObject().put("value", true)); super.onAdLoaded(); } @Override public void onAdFailedToLoad(int errorCode) { // Code to be executed when an ad request fails. notifyListeners("onAdFailedToLoad", new JSObject().put("errorCode", errorCode)); super.onAdFailedToLoad(errorCode); } @Override public void onAdOpened() { // Code to be executed when the ad is displayed. notifyListeners("onAdOpened", new JSObject().put("value", true)); super.onAdOpened(); } @Override public void onAdLeftApplication() { // Code to be executed when the user has left the app. notifyListeners("onAdLeftApplication", new JSObject().put("value", true)); super.onAdLeftApplication(); } @Override public void onAdClosed() { // Code to be executed when when the interstitial ad is closed. notifyListeners("onAdClosed", new JSObject().put("value", true)); super.onAdClosed(); } }); } }); }catch (Exception ex) { call.error(ex.getLocalizedMessage(), ex); } }