Java Code Examples for com.getcapacitor.JSObject#put()
The following examples show how to use
com.getcapacitor.JSObject#put() .
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: BackgroundTask.java From OsmGo with MIT License | 6 votes |
@PluginMethod(returnType=PluginMethod.RETURN_CALLBACK) public void beforeExit(PluginCall call) { String taskId = ""; /* serviceIntent = new Intent(getActivity(), BackgroundTaskService.class); serviceIntent.putExtra("taskId", call.getCallbackId()); getActivity().startService(serviceIntent); */ // No-op for now as Android has less strict requirements for background tasks JSObject ret = new JSObject(); ret.put("taskId", call.getCallbackId()); call.success(ret); }
Example 2
Source File: Camera.java From OsmGo with MIT License | 6 votes |
private void showPrompt(final PluginCall call) { // We have all necessary permissions, open the camera JSObject fromPhotos = new JSObject(); fromPhotos.put("title", "From Photos"); JSObject takePicture = new JSObject(); takePicture.put("title", "Take Picture"); Object[] options = new Object[] { fromPhotos, takePicture }; Dialogs.actions(getActivity(), options, new Dialogs.OnSelectListener() { @Override public void onSelect(int index) { if (index == 0) { openPhotos(call); } else if (index == 1) { openCamera(call); } } }); }
Example 3
Source File: PushNotifications.java From OsmGo with MIT License | 6 votes |
@Override protected void handleOnNewIntent(Intent data) { super.handleOnNewIntent(data); Bundle bundle = data.getExtras(); if(bundle != null && bundle.containsKey("google.message_id")) { JSObject notificationJson = new JSObject(); JSObject dataObject = new JSObject(); for (String key : bundle.keySet()) { if (key.equals("google.message_id")) { notificationJson.put("id", bundle.get(key)); } else { Object value = bundle.get(key); String valueStr = (value != null) ? value.toString() : null; dataObject.put(key, valueStr); } } notificationJson.put("data", dataObject); JSObject actionJson = new JSObject(); actionJson.put("actionId", "tap"); actionJson.put("notification", notificationJson); notifyListeners("pushNotificationActionPerformed", actionJson, true); } }
Example 4
Source File: Device.java From OsmGo with MIT License | 6 votes |
@PluginMethod() public void getInfo(PluginCall call) { JSObject r = new JSObject(); r.put("memUsed", getMemUsed()); r.put("diskFree", getDiskFree()); r.put("diskTotal", getDiskTotal()); r.put("model", android.os.Build.MODEL); r.put("osVersion", android.os.Build.VERSION.RELEASE); r.put("appVersion", getAppVersion()); r.put("platform", getPlatform()); r.put("manufacturer", android.os.Build.MANUFACTURER); r.put("uuid", getUuid()); r.put("batteryLevel", getBatteryLevel()); r.put("isCharging", isCharging()); r.put("isVirtual", isVirtual()); call.success(r); }
Example 5
Source File: App.java From OsmGo with MIT License | 6 votes |
/** * Handle ACTION_VIEW intents to store a URL that was used to open the app * @param intent */ @Override protected void handleOnNewIntent(Intent intent) { super.handleOnNewIntent(intent); final String intentString = intent.getDataString(); // read intent String action = intent.getAction(); Uri url = intent.getData(); if (!Intent.ACTION_VIEW.equals(action) || url == null) { return; } JSObject ret = new JSObject(); ret.put("url", url.toString()); notifyListeners(EVENT_URL_OPEN, ret, true); }
Example 6
Source File: TwitterProviderHandler.java From capacitor-firebase-auth with MIT License | 5 votes |
@Override public void fillResult(AuthCredential credential, JSObject jsResult) { if (credential != null) { jsResult.put("idToken", this.getCredentialParts(credential, "getAccessToken")); jsResult.put("secret", this.getCredentialParts(credential, "getSecret")); } }
Example 7
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 8
Source File: App.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void getLaunchUrl(PluginCall call) { Uri launchUri = bridge.getIntentUri(); if (launchUri != null) { JSObject d = new JSObject(); d.put("url", launchUri.toString()); call.success(d); } else { call.success(); } }
Example 9
Source File: LocalNotification.java From OsmGo with MIT License | 5 votes |
public static JSObject buildLocalNotificationPendingList(List<String> ids) { JSObject result = new JSObject(); JSArray jsArray = new JSArray(); for (String id : ids) { JSObject notification = new JSObject(); notification.put("id", id); jsArray.put(notification); } result.put("notifications", jsArray); return result; }
Example 10
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 11
Source File: Accessibility.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void isScreenReaderEnabled(PluginCall call) { Log.d(getLogTag(), "Checking for screen reader"); Log.d(getLogTag(), "Is it enabled? " + am.isTouchExplorationEnabled()); JSObject ret = new JSObject(); ret.put("value", am.isTouchExplorationEnabled()); call.success(ret); }
Example 12
Source File: PushNotifications.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void createChannel(PluginCall call) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { JSObject channel = new JSObject(); channel.put(CHANNEL_ID, call.getString(CHANNEL_ID)); channel.put(CHANNEL_NAME, call.getString(CHANNEL_NAME)); channel.put(CHANNEL_DESCRIPTION, call.getString(CHANNEL_DESCRIPTION, "")); channel.put(CHANNEL_VISIBILITY, call.getInt(CHANNEL_VISIBILITY, NotificationCompat.VISIBILITY_PUBLIC)); channel.put(CHANNEL_IMPORTANCE, call.getInt(CHANNEL_IMPORTANCE)); createChannel(channel); call.success(); } else { call.unavailable(); } }
Example 13
Source File: Permissions.java From OsmGo with MIT License | 5 votes |
private void checkPerm(String perm, PluginCall call) { JSObject ret = new JSObject(); if (ContextCompat.checkSelfPermission(getContext(), perm) == PackageManager.PERMISSION_DENIED) { ret.put("state", "denied"); } else if (ContextCompat.checkSelfPermission(getContext(), perm) == PackageManager.PERMISSION_GRANTED) { ret.put("state", "granted"); } else { ret.put("state", "prompt"); } call.resolve(ret); }
Example 14
Source File: PushNotifications.java From OsmGo with MIT License | 4 votes |
public void sendError(String error) { JSObject data = new JSObject(); data.put("error", error); notifyListeners(EVENT_TOKEN_ERROR, data, true); }
Example 15
Source File: Permissions.java From OsmGo with MIT License | 4 votes |
private void checkNotifications(PluginCall call) { boolean areEnabled = NotificationManagerCompat.from(getContext()).areNotificationsEnabled(); JSObject ret = new JSObject(); ret.put("state", areEnabled ? "granted" : "denied"); call.resolve(ret); }
Example 16
Source File: Ad.java From admob-plus with MIT License | 4 votes |
void emitEvent(String eventName) { JSObject data = new JSObject(); data.put("id", this.id); this.plugin.getBridge().triggerDocumentJSEvent(String.format("admob.%s.%s", this.getAdType(), eventName), data.toString()); }
Example 17
Source File: Permissions.java From OsmGo with MIT License | 4 votes |
private void checkClipboard(PluginCall call) { JSObject ret = new JSObject(); ret.put("state", "granted"); call.resolve(ret); }
Example 18
Source File: LocalNotifications.java From OsmGo with MIT License | 4 votes |
@PluginMethod() public void areEnabled(PluginCall call) { JSObject data = new JSObject(); data.put("value", manager.areNotificationsEnabled()); call.success(data); }
Example 19
Source File: App.java From OsmGo with MIT License | 4 votes |
public void fireChange(boolean isActive) { Log.d(getLogTag(), "Firing change: " + isActive); JSObject data = new JSObject(); data.put("isActive", isActive); notifyListeners(EVENT_STATE_CHANGE, data, true); }
Example 20
Source File: ExifWrapper.java From OsmGo with MIT License | 4 votes |
public void p(JSObject o, String tag) { String val = exif.getAttribute(tag); o.put(tag, val); }