Java Code Examples for com.getcapacitor.PluginCall#getString()
The following examples show how to use
com.getcapacitor.PluginCall#getString() .
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: AdMob.java From capacitor-admob with MIT License | 6 votes |
@PluginMethod() public void initialize(PluginCall call) { /* Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 */ String appId = call.getString("appId", "ca-app-pub-3940256099942544~3347511713"); try { MobileAds.initialize(this.getContext(), appId); mViewGroup = (ViewGroup) ((ViewGroup) getActivity().findViewById(android.R.id.content)).getChildAt(0); call.success(); }catch (Exception ex) { call.error(ex.getLocalizedMessage(), ex); } }
Example 2
Source File: App.java From OsmGo with MIT License | 6 votes |
@PluginMethod() public void canOpenUrl(PluginCall call) { String url = call.getString("url"); if (url == null) { call.error("Must supply a url"); return; } Context ctx = this.getActivity().getApplicationContext(); final PackageManager pm = ctx.getPackageManager(); JSObject ret = new JSObject(); try { pm.getPackageInfo(url, PackageManager.GET_ACTIVITIES); ret.put("value", true); call.success(ret); return; } catch(PackageManager.NameNotFoundException e) { Log.e(getLogTag(), "Package name '"+url+"' not found!"); } ret.put("value", false); call.success(ret); }
Example 3
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 4
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 5
Source File: Filesystem.java From OsmGo with MIT License | 6 votes |
@PluginMethod() public void deleteFile(PluginCall call) { saveCall(call); String file = call.getString("path"); String directory = getDirectoryParameter(call); File fileObject = getFileObject(file, directory); if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_DELETE_FILE_PERMISSIONS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { if (!fileObject.exists()) { call.error("File does not exist"); return; } boolean deleted = fileObject.delete(); if(deleted == false) { call.error("Unable to delete file"); } else { call.success(); } } }
Example 6
Source File: FCMPlugin.java From capacitor-fcm with MIT License | 5 votes |
@PluginMethod() public void subscribeTo(final PluginCall call) { final String topicName = call.getString("topic"); FirebaseMessaging .getInstance() .subscribeToTopic(topicName) .addOnSuccessListener(aVoid -> { JSObject ret = new JSObject(); ret.put("message", "Subscribed to topic " + topicName); call.success(ret); }) .addOnFailureListener(e -> call.error("Cant subscribe to topic" + topicName, e)); }
Example 7
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 8
Source File: Modals.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void prompt(final PluginCall call) { final Activity c = this.getActivity(); final String title = call.getString("title"); final String message = call.getString("message"); final String okButtonTitle = call.getString("okButtonTitle", "OK"); final String cancelButtonTitle = call.getString("cancelButtonTitle", "Cancel"); final String inputPlaceholder = call.getString("inputPlaceholder", ""); 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.prompt(c, message, title, okButtonTitle, cancelButtonTitle, inputPlaceholder, new Dialogs.OnResultListener() { @Override public void onResult(boolean value, boolean didCancel, String inputValue) { JSObject ret = new JSObject(); ret.put("cancelled", didCancel); ret.put("value", inputValue == null ? "" : inputValue); call.success(ret); } }); }
Example 9
Source File: Share.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void share(PluginCall call) { String title = call.getString("title", ""); String text = call.getString("text"); String url = call.getString("url"); String dialogTitle = call.getString("dialogTitle", "Share"); if (text == null && url == null) { call.error("Must provide a URL or Message"); return; } // If they supplied both fields, concat em if (text != null && url != null) { text = text + " " + url; } else if(url != null) { text = url; } Intent intent = new Intent(Intent.ACTION_SEND); intent.setTypeAndNormalize("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, text); if (title != null) { intent.putExtra(Intent.EXTRA_SUBJECT, title); } Intent chooser = Intent.createChooser(intent, dialogTitle); chooser.addCategory(Intent.CATEGORY_DEFAULT); getActivity().startActivity(chooser); call.success(); }
Example 10
Source File: PushNotifications.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void deleteChannel(PluginCall call) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { String channelId = call.getString("id"); notificationManager.deleteNotificationChannel(channelId); call.success(); } else { call.unavailable(); } }
Example 11
Source File: Filesystem.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void mkdir(PluginCall call) { saveCall(call); String path = call.getString("path"); String directory = getDirectoryParameter(call); boolean intermediate = call.getBoolean("createIntermediateDirectories", false).booleanValue(); File fileObject = getFileObject(path, directory); if (fileObject.exists()) { call.error("Directory exists"); return; } if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_WRITE_FOLDER_PERMISSIONS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { boolean created = false; if (intermediate) { created = fileObject.mkdirs(); } else { created = fileObject.mkdir(); } if(created == false) { call.error("Unable to create directory, unknown reason"); } else { call.success(); } } }
Example 12
Source File: AdmobPlus.java From admob-plus with MIT License | 5 votes |
@PluginMethod() public void echo(PluginCall call) { String value = call.getString("value"); JSObject ret = new JSObject(); ret.put("value", value); call.success(ret); }
Example 13
Source File: DownloaderPlugin.java From capacitor-downloader with MIT License | 5 votes |
@PluginMethod() public void getPath(PluginCall call) { String id = call.getString("id"); DownloadData data = downloadsData.get(id); JSObject jsObject = new JSObject(); if (data != null) { jsObject.put("value", data.getPath()); } call.resolve(jsObject); }
Example 14
Source File: DownloaderPlugin.java From capacitor-downloader with MIT License | 5 votes |
@PluginMethod(returnType = PluginMethod.RETURN_CALLBACK) public void start(PluginCall call) { String id = call.getString("id"); Manager manager = Manager.getInstance(); DownloadData data = downloadsData.get(id); Request request = downloadsRequest.get(id); call.save(); data.setCallback(call); if (request != null) { request.setListener(new Listener()); } manager.start(id); }
Example 15
Source File: Filesystem.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void rmdir(PluginCall call) { saveCall(call); String path = call.getString("path"); String directory = getDirectoryParameter(call); Boolean recursive = call.getBoolean("recursive", false); File fileObject = getFileObject(path, directory); if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_DELETE_FOLDER_PERMISSIONS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { if (!fileObject.exists()) { call.error("Directory does not exist"); return; } if (fileObject.isDirectory() && fileObject.listFiles().length != 0 && !recursive) { call.error("Directory is not empty"); return; } boolean deleted = false; try { deleteRecursively(fileObject); deleted = true; } catch (IOException ignored) { } if(deleted == false) { call.error("Unable to delete directory, unknown reason"); } else { call.success(); } } }
Example 16
Source File: FCMPlugin.java From capacitor-fcm with MIT License | 5 votes |
@PluginMethod() public void unsubscribeFrom(final PluginCall call) { final String topicName = call.getString("topic"); FirebaseMessaging .getInstance() .unsubscribeFromTopic(topicName) .addOnSuccessListener(aVoid -> { JSObject ret = new JSObject(); ret.put("message", "Unsubscribed from topic " + topicName); call.success(ret); }) .addOnFailureListener(e -> call.error("Cant unsubscribe from topic" + topicName, e)); }
Example 17
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 18
Source File: DownloaderPlugin.java From capacitor-downloader with MIT License | 4 votes |
@PluginMethod() public void cancel(PluginCall call) { String id = call.getString("id"); Manager manager = Manager.getInstance(); manager.cancel(id); }
Example 19
Source File: DownloaderPlugin.java From capacitor-downloader with MIT License | 4 votes |
@PluginMethod() public void resume(PluginCall call) { String id = call.getString("id"); Manager manager = Manager.getInstance(); manager.resume(id); }
Example 20
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); } }