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();
}
}
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();
}
}
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<>();
}
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;
}
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);
}
Aggregations