use of com.getcapacitor.JSObject in project capacitor-plugins by ionic-team.
the class GeolocationPlugin method getJSObjectForLocation.
private JSObject getJSObjectForLocation(Location location) {
JSObject ret = new JSObject();
JSObject coords = new JSObject();
ret.put("coords", coords);
ret.put("timestamp", location.getTime());
coords.put("latitude", location.getLatitude());
coords.put("longitude", location.getLongitude());
coords.put("accuracy", location.getAccuracy());
coords.put("altitude", location.getAltitude());
if (Build.VERSION.SDK_INT >= 26) {
coords.put("altitudeAccuracy", location.getVerticalAccuracyMeters());
}
coords.put("speed", location.getSpeed());
coords.put("heading", location.getBearing());
return ret;
}
use of com.getcapacitor.JSObject in project capacitor-plugins by ionic-team.
the class FilesystemPlugin method stat.
@PluginMethod
public void stat(PluginCall call) {
String path = call.getString("path");
String directory = getDirectoryParameter(call);
File fileObject = implementation.getFileObject(path, directory);
if (isPublicDirectory(directory) && !isStoragePermissionGranted()) {
requestAllPermissions(call, "permissionCallback");
} else {
if (!fileObject.exists()) {
call.reject("File does not exist");
return;
}
JSObject data = new JSObject();
data.put("type", fileObject.isDirectory() ? "directory" : "file");
data.put("size", fileObject.length());
data.put("mtime", fileObject.lastModified());
data.put("uri", Uri.fromFile(fileObject).toString());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try {
BasicFileAttributes attr = Files.readAttributes(fileObject.toPath(), BasicFileAttributes.class);
// use whichever is the oldest between creationTime and lastAccessTime
if (attr.creationTime().toMillis() < attr.lastAccessTime().toMillis()) {
data.put("ctime", attr.creationTime().toMillis());
} else {
data.put("ctime", attr.lastAccessTime().toMillis());
}
} catch (Exception ex) {
}
} else {
data.put("ctime", null);
}
call.resolve(data);
}
}
use of com.getcapacitor.JSObject in project capacitor-plugins by ionic-team.
the class FilesystemPlugin method readFile.
@PluginMethod
public void readFile(PluginCall call) {
String path = call.getString("path");
String directory = getDirectoryParameter(call);
String encoding = call.getString("encoding");
Charset charset = implementation.getEncoding(encoding);
if (encoding != null && charset == null) {
call.reject("Unsupported encoding provided: " + encoding);
return;
}
if (isPublicDirectory(directory) && !isStoragePermissionGranted()) {
requestAllPermissions(call, "permissionCallback");
} else {
try {
String dataStr = implementation.readFile(path, directory, charset);
JSObject ret = new JSObject();
ret.putOpt("data", dataStr);
call.resolve(ret);
} catch (FileNotFoundException ex) {
call.reject("File does not exist", ex);
} catch (IOException ex) {
call.reject("Unable to read file", ex);
} catch (JSONException ex) {
call.reject("Unable to return value for reading file", ex);
}
}
}
use of com.getcapacitor.JSObject in project capacitor-plugins by ionic-team.
the class FilesystemPlugin method readdir.
@PluginMethod
public void readdir(PluginCall call) {
String path = call.getString("path");
String directory = getDirectoryParameter(call);
if (isPublicDirectory(directory) && !isStoragePermissionGranted()) {
requestAllPermissions(call, "permissionCallback");
} else {
try {
String[] files = implementation.readdir(path, directory);
if (files != null) {
JSObject ret = new JSObject();
ret.put("files", JSArray.from(files));
call.resolve(ret);
} else {
call.reject("Unable to read directory");
}
} catch (DirectoryNotFoundException ex) {
call.reject(ex.getMessage());
}
}
}
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();
}
}
Aggregations