Search in sources :

Example 51 with PluginMethod

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

Example 52 with PluginMethod

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();
}
Also used : Uri(android.net.Uri) PluginMethod(com.getcapacitor.PluginMethod)

Example 53 with PluginMethod

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

Example 54 with PluginMethod

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);
}
Also used : PackageManager(android.content.pm.PackageManager) JSObject(com.getcapacitor.JSObject) Intent(android.content.Intent) PluginMethod(com.getcapacitor.PluginMethod)

Example 55 with PluginMethod

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);
}
Also used : Context(android.content.Context) PackageManager(android.content.pm.PackageManager) 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