use of com.getcapacitor.PluginMethod in project capacitor-plugins by ionic-team.
the class StoragePlugin method get.
@PluginMethod
public void get(PluginCall call) {
String key = call.getString("key");
if (key == null) {
call.reject("Must provide key");
return;
}
String value = storage.get(key);
JSObject ret = new JSObject();
ret.put("value", value == null ? JSObject.NULL : value);
call.resolve(ret);
}
use of com.getcapacitor.PluginMethod in project capacitor-plugins by ionic-team.
the class BrowserPlugin method open.
@PluginMethod
public void open(PluginCall call) {
// get the URL
String urlString = call.getString("url");
if (urlString == null) {
call.reject("Must provide a URL to open");
return;
}
if (urlString.isEmpty()) {
call.reject("URL must not be empty");
return;
}
Uri url;
try {
url = Uri.parse(urlString);
} catch (Exception ex) {
call.reject(ex.getLocalizedMessage());
return;
}
// get the toolbar color, if provided
String colorString = call.getString("toolbarColor");
Integer toolbarColor = null;
if (colorString != null)
try {
toolbarColor = WebColor.parseColor(colorString);
} catch (IllegalArgumentException ex) {
Logger.error(getLogTag(), "Invalid color provided for toolbarColor. Using default", null);
}
// open the browser and finish
implementation.open(url, toolbarColor);
call.resolve();
}
use of com.getcapacitor.PluginMethod in project capacitor-plugins by ionic-team.
the class CameraPlugin method requestPermissions.
@Override
@PluginMethod
public void requestPermissions(PluginCall call) {
// it is not defined in the manifest then we don't need to prompt and it will just work.
if (isPermissionDeclared(CAMERA)) {
// just request normally
super.requestPermissions(call);
} else {
// the manifest does not define camera permissions, so we need to decide what to do
// first, extract the permissions being requested
JSArray providedPerms = call.getArray("permissions");
List<String> permsList = null;
try {
permsList = providedPerms.toList();
} catch (JSONException e) {
}
if (permsList != null && permsList.size() == 1 && permsList.contains(CAMERA)) {
// the only thing being asked for was the camera so we can just return the current state
checkPermissions(call);
} else {
// we need to ask about photos so request storage permissions
requestPermissionForAlias(PHOTOS, call, "checkPermissions");
}
}
}
use of com.getcapacitor.PluginMethod in project capacitor-plugins by ionic-team.
the class AppLauncherPlugin method openUrl.
@PluginMethod
public void openUrl(PluginCall call) {
String url = call.getString("url");
if (url == null) {
call.reject("Must provide a url to open");
return;
}
JSObject ret = new JSObject();
final PackageManager manager = getContext().getPackageManager();
Intent launchIntent = new Intent(Intent.ACTION_VIEW);
launchIntent.setData(Uri.parse(url));
try {
getActivity().startActivity(launchIntent);
ret.put("completed", true);
} catch (Exception ex) {
launchIntent = manager.getLaunchIntentForPackage(url);
try {
getActivity().startActivity(launchIntent);
ret.put("completed", true);
} catch (Exception expgk) {
ret.put("completed", false);
}
}
call.resolve(ret);
}
use of com.getcapacitor.PluginMethod in project capacitor-plugins by ionic-team.
the class AppLauncherPlugin method canOpenUrl.
@PluginMethod
public void canOpenUrl(PluginCall call) {
String url = call.getString("url");
if (url == null) {
call.reject("Must supply a url");
return;
}
Context ctx = this.getActivity().getApplicationContext();
final PackageManager pm = ctx.getPackageManager();
JSObject ret = new JSObject();
try {
pm.getPackageInfo(url, PackageManager.GET_ACTIVITIES);
ret.put("value", true);
call.resolve(ret);
return;
} catch (PackageManager.NameNotFoundException e) {
Logger.error(getLogTag(), "Package name '" + url + "' not found!", null);
}
ret.put("value", false);
call.resolve(ret);
}
Aggregations