Search in sources :

Example 41 with PluginMethod

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");
    }
}
Also used : PluginCall(com.getcapacitor.PluginCall) PluginMethod(com.getcapacitor.PluginMethod)

Example 42 with PluginMethod

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);
    }
}
Also used : JSObject(com.getcapacitor.JSObject) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) DirectoryExistsException(com.capacitorjs.plugins.filesystem.exceptions.DirectoryExistsException) CopyFailedException(com.capacitorjs.plugins.filesystem.exceptions.CopyFailedException) JSONException(org.json.JSONException) DirectoryNotFoundException(com.capacitorjs.plugins.filesystem.exceptions.DirectoryNotFoundException) PluginMethod(com.getcapacitor.PluginMethod)

Example 43 with PluginMethod

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);
        }
    }
}
Also used : Charset(java.nio.charset.Charset) JSObject(com.getcapacitor.JSObject) JSONException(org.json.JSONException) PluginMethod(com.getcapacitor.PluginMethod)

Example 44 with PluginMethod

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());
        }
    }
}
Also used : DirectoryNotFoundException(com.capacitorjs.plugins.filesystem.exceptions.DirectoryNotFoundException) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 45 with PluginMethod

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

Aggregations

PluginMethod (com.getcapacitor.PluginMethod)120 JSObject (com.getcapacitor.JSObject)93 JSONException (org.json.JSONException)18 MyRunnable (com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable)13 JSONObject (org.json.JSONObject)13 JSArray (com.getcapacitor.JSArray)12 Radar (io.radar.sdk.Radar)11 Location (android.location.Location)8 Intent (android.content.Intent)7 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 Uri (android.net.Uri)5 LatLng (com.google.android.libraries.maps.model.LatLng)5 GenericAd (admob.plus.core.GenericAd)4 GoogleSignInAccount (com.google.android.gms.auth.api.signin.GoogleSignInAccount)4 Gson (com.google.gson.Gson)4 PackageManager (android.content.pm.PackageManager)3 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)3 User (io.ionic.demo.ecommerce.data.model.User)3 Context (android.content.Context)2