use of com.getcapacitor.PluginMethod in project capacitor-plugins by ionic-team.
the class GeolocationPlugin method clearWatch.
/**
* Removes an active geolocation watch.
*
* @param call Plugin call
*/
@SuppressWarnings("MissingPermission")
@PluginMethod
public void clearWatch(PluginCall call) {
String callbackId = call.getString("id");
if (callbackId != null) {
PluginCall removed = watchingCalls.remove(callbackId);
if (removed != null) {
removed.release(bridge);
}
if (watchingCalls.size() == 0) {
implementation.clearLocationUpdates();
}
call.resolve();
} else {
call.reject("Watch call id must be provided");
}
}
use of com.getcapacitor.PluginMethod 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.PluginMethod 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.PluginMethod 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.PluginMethod 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();
}
Aggregations