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