Search in sources :

Example 61 with JSObject

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

the class NotificationChannelManager method createChannel.

public void createChannel(PluginCall call) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        JSObject channel = new JSObject();
        if (call.getString(CHANNEL_ID) != null) {
            channel.put(CHANNEL_ID, call.getString(CHANNEL_ID));
        } else {
            call.reject("Channel missing identifier");
            return;
        }
        if (call.getString(CHANNEL_NAME) != null) {
            channel.put(CHANNEL_NAME, call.getString(CHANNEL_NAME));
        } else {
            call.reject("Channel missing name");
            return;
        }
        if (call.getInt(CHANNEL_IMPORTANCE) != null) {
            channel.put(CHANNEL_IMPORTANCE, call.getInt(CHANNEL_IMPORTANCE));
        } else {
            call.reject("Channel missing importance");
            return;
        }
        channel.put(CHANNEL_DESCRIPTION, call.getString(CHANNEL_DESCRIPTION, ""));
        channel.put(CHANNEL_VISIBILITY, call.getInt(CHANNEL_VISIBILITY, NotificationCompat.VISIBILITY_PUBLIC));
        channel.put(CHANNEL_SOUND, call.getString(CHANNEL_SOUND, null));
        channel.put(CHANNEL_VIBRATE, call.getBoolean(CHANNEL_VIBRATE, false));
        channel.put(CHANNEL_USE_LIGHTS, call.getBoolean(CHANNEL_USE_LIGHTS, false));
        channel.put(CHANNEL_LIGHT_COLOR, call.getString(CHANNEL_LIGHT_COLOR, null));
        createChannel(channel);
        call.resolve();
    } else {
        call.unavailable();
    }
}
Also used : JSObject(com.getcapacitor.JSObject)

Example 62 with JSObject

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

the class NotificationChannelManager method listChannels.

public void listChannels(PluginCall call) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        List<NotificationChannel> notificationChannels = notificationManager.getNotificationChannels();
        JSArray channels = new JSArray();
        for (NotificationChannel notificationChannel : notificationChannels) {
            JSObject channel = new JSObject();
            channel.put(CHANNEL_ID, notificationChannel.getId());
            channel.put(CHANNEL_NAME, notificationChannel.getName());
            channel.put(CHANNEL_DESCRIPTION, notificationChannel.getDescription());
            channel.put(CHANNEL_IMPORTANCE, notificationChannel.getImportance());
            channel.put(CHANNEL_VISIBILITY, notificationChannel.getLockscreenVisibility());
            channel.put(CHANNEL_SOUND, notificationChannel.getSound());
            channel.put(CHANNEL_VIBRATE, notificationChannel.shouldVibrate());
            channel.put(CHANNEL_USE_LIGHTS, notificationChannel.shouldShowLights());
            channel.put(CHANNEL_LIGHT_COLOR, String.format("#%06X", (0xFFFFFF & notificationChannel.getLightColor())));
            Logger.debug(Logger.tags("NotificationChannel"), "visibility " + notificationChannel.getLockscreenVisibility());
            Logger.debug(Logger.tags("NotificationChannel"), "importance " + notificationChannel.getImportance());
            channels.put(channel);
        }
        JSObject result = new JSObject();
        result.put("channels", channels);
        call.resolve(result);
    } else {
        call.unavailable();
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) JSArray(com.getcapacitor.JSArray) JSObject(com.getcapacitor.JSObject)

Example 63 with JSObject

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

the class NotificationStorage method getSavedNotifications.

public List<LocalNotification> getSavedNotifications() {
    SharedPreferences storage = getStorage(NOTIFICATION_STORE_ID);
    Map<String, ?> all = storage.getAll();
    if (all != null) {
        ArrayList<LocalNotification> notifications = new ArrayList<>();
        for (String key : all.keySet()) {
            String notificationString = (String) all.get(key);
            JSObject jsNotification = getNotificationFromJSONString(notificationString);
            if (jsNotification != null) {
                try {
                    LocalNotification notification = LocalNotification.buildNotificationFromJSObject(jsNotification);
                    notifications.add(notification);
                } catch (ParseException ex) {
                }
            }
        }
        return notifications;
    }
    return new ArrayList<>();
}
Also used : SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) JSObject(com.getcapacitor.JSObject) ParseException(java.text.ParseException)

Example 64 with JSObject

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

the class NotificationStorage method getSavedNotificationAsJSObject.

public JSObject getSavedNotificationAsJSObject(String key) {
    SharedPreferences storage = getStorage(NOTIFICATION_STORE_ID);
    String notificationString = storage.getString(key, null);
    if (notificationString == null) {
        return null;
    }
    JSObject jsNotification;
    try {
        jsNotification = new JSObject(notificationString);
    } catch (JSONException ex) {
        return null;
    }
    return jsNotification;
}
Also used : SharedPreferences(android.content.SharedPreferences) JSObject(com.getcapacitor.JSObject) JSONException(org.json.JSONException)

Example 65 with JSObject

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

the class SharePlugin method canShare.

@PluginMethod
public void canShare(PluginCall call) {
    JSObject callResult = new JSObject();
    callResult.put("value", true);
    call.resolve(callResult);
}
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