Search in sources :

Example 81 with PluginMethod

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

the class AppPlugin method minimizeApp.

@PluginMethod
public void minimizeApp(PluginCall call) {
    Intent startMain = new Intent(Intent.ACTION_MAIN);
    startMain.addCategory(Intent.CATEGORY_HOME);
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    getActivity().startActivity(startMain);
    call.resolve();
}
Also used : Intent(android.content.Intent) PluginMethod(com.getcapacitor.PluginMethod)

Example 82 with PluginMethod

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

the class FilesystemPlugin method getUri.

@PluginMethod
public void getUri(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 {
        JSObject data = new JSObject();
        data.put("uri", Uri.fromFile(fileObject).toString());
        call.resolve(data);
    }
}
Also used : JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 83 with PluginMethod

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

the class FilesystemPlugin method writeFile.

@PluginMethod
public void writeFile(PluginCall call) {
    String path = call.getString("path");
    String data = call.getString("data");
    Boolean recursive = call.getBoolean("recursive", false);
    if (path == null) {
        Logger.error(getLogTag(), "No path or filename retrieved from call", null);
        call.reject("NO_PATH");
        return;
    }
    if (data == null) {
        Logger.error(getLogTag(), "No data retrieved from call", null);
        call.reject("NO_DATA");
        return;
    }
    String directory = getDirectoryParameter(call);
    if (directory != null) {
        if (isPublicDirectory(directory) && !isStoragePermissionGranted()) {
            requestAllPermissions(call, "permissionCallback");
        } else {
            // create directory because it might not exist
            File androidDir = implementation.getDirectory(directory);
            if (androidDir != null) {
                if (androidDir.exists() || androidDir.mkdirs()) {
                    // path might include directories as well
                    File fileObject = new File(androidDir, path);
                    if (fileObject.getParentFile().exists() || (recursive && fileObject.getParentFile().mkdirs())) {
                        saveFile(call, fileObject, data);
                    } else {
                        call.reject("Parent folder doesn't exist");
                    }
                } else {
                    Logger.error(getLogTag(), "Not able to create '" + directory + "'!", null);
                    call.reject("NOT_CREATED_DIR");
                }
            } else {
                Logger.error(getLogTag(), "Directory ID '" + directory + "' is not supported by plugin", null);
                call.reject("INVALID_DIR");
            }
        }
    } else {
        // check file:// or no scheme uris
        Uri u = Uri.parse(path);
        if (u.getScheme() == null || u.getScheme().equals("file")) {
            File fileObject = new File(u.getPath());
            // TODO to prevent permission checking we need a property from the call
            if (!isStoragePermissionGranted()) {
                requestAllPermissions(call, "permissionCallback");
            } else {
                if (fileObject.getParentFile() == null || fileObject.getParentFile().exists() || (recursive && fileObject.getParentFile().mkdirs())) {
                    saveFile(call, fileObject, data);
                } else {
                    call.reject("Parent folder doesn't exist");
                }
            }
        } else {
            call.reject(u.getScheme() + " scheme not supported");
        }
    }
}
Also used : Uri(android.net.Uri) PluginMethod(com.getcapacitor.PluginMethod)

Example 84 with PluginMethod

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

the class ActionSheetPlugin method showActions.

@PluginMethod
public void showActions(final PluginCall call) {
    String title = call.getString("title");
    JSArray options = call.getArray("options");
    if (title == null) {
        call.reject("Must supply a title");
        return;
    }
    if (options == null) {
        call.reject("Must supply options");
        return;
    }
    if (getActivity().isFinishing()) {
        call.reject("App is finishing");
        return;
    }
    try {
        List<Object> optionsList = options.toList();
        ActionSheetOption[] actionOptions = new ActionSheetOption[optionsList.size()];
        for (int i = 0; i < optionsList.size(); i++) {
            JSObject o = JSObject.fromJSONObject((JSONObject) optionsList.get(i));
            String titleOption = o.getString("title", "");
            actionOptions[i] = new ActionSheetOption(titleOption);
        }
        implementation.setTitle(title);
        implementation.setOptions(actionOptions);
        implementation.setCancelable(false);
        implementation.setOnSelectedListener(index -> {
            JSObject ret = new JSObject();
            ret.put("index", index);
            call.resolve(ret);
            implementation.dismiss();
        });
        implementation.show(getActivity().getSupportFragmentManager(), "capacitorModalsActionSheet");
    } catch (JSONException ex) {
        Logger.error("JSON error processing an option for showActions", ex);
        call.reject("JSON error processing an option for showActions", ex);
    }
}
Also used : JSArray(com.getcapacitor.JSArray) JSObject(com.getcapacitor.JSObject) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 85 with PluginMethod

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

the class LocalNotificationsPlugin method registerActionTypes.

@PluginMethod
public void registerActionTypes(PluginCall call) {
    JSArray types = call.getArray("types");
    Map<String, NotificationAction[]> typesArray = NotificationAction.buildTypes(types);
    notificationStorage.writeActionGroup(typesArray);
    call.resolve();
}
Also used : JSArray(com.getcapacitor.JSArray) 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