Search in sources :

Example 71 with JSObject

use of com.getcapacitor.JSObject in project capacitor-plugins by ionic-team.

the class PushNotificationsPlugin method removeDeliveredNotifications.

@PluginMethod
public void removeDeliveredNotifications(PluginCall call) {
    JSArray notifications = call.getArray("notifications");
    List<Integer> ids = new ArrayList<>();
    try {
        for (Object o : notifications.toList()) {
            if (o instanceof JSONObject) {
                JSObject notif = JSObject.fromJSONObject((JSONObject) o);
                Integer id = notif.getInteger("id");
                ids.add(id);
            } else {
                call.reject("Expected notifications to be a list of notification objects");
            }
        }
    } catch (JSONException e) {
        call.reject(e.getMessage());
    }
    for (int id : ids) {
        notificationManager.cancel(id);
    }
    call.resolve();
}
Also used : JSONObject(org.json.JSONObject) JSArray(com.getcapacitor.JSArray) ArrayList(java.util.ArrayList) JSObject(com.getcapacitor.JSObject) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 72 with JSObject

use of com.getcapacitor.JSObject in project capacitor-plugins by ionic-team.

the class PushNotificationsPlugin method handleOnNewIntent.

@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);
    }
}
Also used : Bundle(android.os.Bundle) JSObject(com.getcapacitor.JSObject) JSONObject(org.json.JSONObject) JSObject(com.getcapacitor.JSObject)

Example 73 with JSObject

use of com.getcapacitor.JSObject in project capacitor-plugins by ionic-team.

the class DialogPlugin method confirm.

@PluginMethod
public void confirm(final PluginCall call) {
    final AppCompatActivity activity = 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");
    if (title == null || message == null) {
        call.reject("Please provide a title or message for the alert");
        return;
    }
    if (activity.isFinishing()) {
        call.reject("App is finishing");
        return;
    }
    Dialog.confirm(activity, message, title, okButtonTitle, cancelButtonTitle, (value, didCancel, inputValue) -> {
        JSObject ret = new JSObject();
        ret.put("value", value);
        call.resolve(ret);
    });
}
Also used : AppCompatActivity(androidx.appcompat.app.AppCompatActivity) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 74 with JSObject

use of com.getcapacitor.JSObject in project capacitor-plugins by ionic-team.

the class ScreenReaderPlugin method isEnabled.

@SuppressWarnings("unused")
@PluginMethod
public void isEnabled(PluginCall call) {
    JSObject ret = new JSObject();
    ret.put("value", screenReader.isEnabled());
    call.resolve(ret);
}
Also used : JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 75 with JSObject

use of com.getcapacitor.JSObject in project capacitor-plugins by ionic-team.

the class TextZoomPlugin method get.

@PluginMethod
public void get(final PluginCall call) {
    mainHandler.post(() -> {
        JSObject ret = new JSObject();
        ret.put("value", textZoom.get());
        call.resolve(ret);
    });
}
Also used : JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Aggregations

JSObject (com.getcapacitor.JSObject)169 PluginMethod (com.getcapacitor.PluginMethod)93 JSONException (org.json.JSONException)28 JSONObject (org.json.JSONObject)20 MyRunnable (com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable)16 JSArray (com.getcapacitor.JSArray)14 Radar (io.radar.sdk.Radar)12 Uri (android.net.Uri)11 Location (android.location.Location)9 JSONArray (org.json.JSONArray)7 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 ParseException (java.text.ParseException)5 Intent (android.content.Intent)4 FirebaseUser (com.google.firebase.auth.FirebaseUser)4 Gson (com.google.gson.Gson)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4