Search in sources :

Example 76 with PluginMethod

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

the class DevicePlugin method getBatteryInfo.

@PluginMethod
public void getBatteryInfo(PluginCall call) {
    JSObject r = new JSObject();
    r.put("batteryLevel", implementation.getBatteryLevel());
    r.put("isCharging", implementation.isCharging());
    call.resolve(r);
}
Also used : JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 77 with PluginMethod

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

the class DevicePlugin method getId.

@PluginMethod
public void getId(PluginCall call) {
    JSObject r = new JSObject();
    r.put("uuid", implementation.getUuid());
    call.resolve(r);
}
Also used : JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 78 with PluginMethod

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

the class DialogPlugin method alert.

@PluginMethod
public void alert(final PluginCall call) {
    final AppCompatActivity activity = this.getActivity();
    final String title = call.getString("title");
    final String message = call.getString("message");
    final String buttonTitle = call.getString("buttonTitle", "OK");
    if (title == null || message == null) {
        call.reject("Please provide a title or message for the alert");
        return;
    }
    if (activity.isFinishing()) {
        call.reject("App is finishing");
        return;
    }
    Dialog.alert(activity, message, title, buttonTitle, (value, didCancel, inputValue) -> call.resolve());
}
Also used : AppCompatActivity(androidx.appcompat.app.AppCompatActivity) PluginMethod(com.getcapacitor.PluginMethod)

Example 79 with PluginMethod

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

the class DialogPlugin method prompt.

@PluginMethod
public void prompt(final PluginCall call) {
    final AppCompatActivity activity = this.getActivity();
    final String title = call.getString("title");
    final String message = call.getString("message");
    final String okButtonTitle = call.getString("okButtonTitle", "OK");
    final String cancelButtonTitle = call.getString("cancelButtonTitle", "Cancel");
    final String inputPlaceholder = call.getString("inputPlaceholder", "");
    final String inputText = call.getString("inputText", "");
    if (title == null || message == null) {
        call.reject("Please provide a title or message for the alert");
        return;
    }
    if (activity.isFinishing()) {
        call.reject("App is finishing");
        return;
    }
    Dialog.prompt(activity, message, title, okButtonTitle, cancelButtonTitle, inputPlaceholder, inputText, (value, didCancel, inputValue) -> {
        JSObject ret = new JSObject();
        ret.put("cancelled", didCancel);
        ret.put("value", inputValue == null ? "" : inputValue);
        call.resolve(ret);
    });
}
Also used : AppCompatActivity(androidx.appcompat.app.AppCompatActivity) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 80 with PluginMethod

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

the class AppPlugin method getInfo.

@PluginMethod
public void getInfo(PluginCall call) {
    JSObject data = new JSObject();
    try {
        PackageInfo pinfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0);
        ApplicationInfo applicationInfo = getContext().getApplicationInfo();
        int stringId = applicationInfo.labelRes;
        String appName = stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : getContext().getString(stringId);
        data.put("name", appName);
        data.put("id", pinfo.packageName);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            data.put("build", Long.toString(pinfo.getLongVersionCode()));
        } else {
            data.put("build", Integer.toString(pinfo.versionCode));
        }
        data.put("version", pinfo.versionName);
        call.resolve(data);
    } catch (Exception ex) {
        call.reject("Unable to get App Info");
    }
}
Also used : PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) 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