Search in sources :

Example 86 with PluginMethod

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

the class LocalNotificationsPlugin method requestPermissions.

@PluginMethod
public void requestPermissions(PluginCall call) {
    JSObject permissionsResultJSON = new JSObject();
    permissionsResultJSON.put("display", getNotificationPermissionText());
    call.resolve(permissionsResultJSON);
}
Also used : JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 87 with PluginMethod

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

the class PushNotificationsPlugin method getDeliveredNotifications.

@PluginMethod
public void getDeliveredNotifications(PluginCall call) {
    JSArray notifications = new JSArray();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        StatusBarNotification[] activeNotifications = notificationManager.getActiveNotifications();
        for (StatusBarNotification notif : activeNotifications) {
            JSObject jsNotif = new JSObject();
            jsNotif.put("id", notif.getId());
            Notification notification = notif.getNotification();
            if (notification != null) {
                jsNotif.put("title", notification.extras.getCharSequence(Notification.EXTRA_TITLE));
                jsNotif.put("body", notification.extras.getCharSequence(Notification.EXTRA_TEXT));
                jsNotif.put("group", notification.getGroup());
                jsNotif.put("groupSummary", 0 != (notification.flags & Notification.FLAG_GROUP_SUMMARY));
                JSObject extras = new JSObject();
                for (String key : notification.extras.keySet()) {
                    extras.put(key, notification.extras.get(key));
                }
                jsNotif.put("data", extras);
            }
            notifications.put(jsNotif);
        }
    }
    JSObject result = new JSObject();
    result.put("notifications", notifications);
    call.resolve(result);
}
Also used : StatusBarNotification(android.service.notification.StatusBarNotification) JSArray(com.getcapacitor.JSArray) JSObject(com.getcapacitor.JSObject) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) PluginMethod(com.getcapacitor.PluginMethod)

Example 88 with PluginMethod

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

the class SharePlugin method share.

@PluginMethod
public void share(PluginCall call) {
    if (!isPresenting) {
        String title = call.getString("title", "");
        String text = call.getString("text");
        String url = call.getString("url");
        String dialogTitle = call.getString("dialogTitle", "Share");
        if (text == null && url == null) {
            call.reject("Must provide a URL or Message");
            return;
        }
        if (url != null && !isFileUrl(url) && !isHttpUrl(url)) {
            call.reject("Unsupported url");
            return;
        }
        Intent intent = new Intent(Intent.ACTION_SEND);
        if (text != null) {
            // If they supplied both fields, concat them
            if (url != null && isHttpUrl(url))
                text = text + " " + url;
            intent.putExtra(Intent.EXTRA_TEXT, text);
            intent.setTypeAndNormalize("text/plain");
        }
        if (url != null && isHttpUrl(url) && text == null) {
            intent.putExtra(Intent.EXTRA_TEXT, url);
            intent.setTypeAndNormalize("text/plain");
        } else if (url != null && isFileUrl(url)) {
            String type = getMimeType(url);
            if (type == null) {
                type = "*/*";
            }
            intent.setType(type);
            Uri fileUrl = FileProvider.getUriForFile(getActivity(), getContext().getPackageName() + ".fileprovider", new File(Uri.parse(url).getPath()));
            intent.putExtra(Intent.EXTRA_STREAM, fileUrl);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                intent.setDataAndType(fileUrl, type);
            }
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
        if (title != null) {
            intent.putExtra(Intent.EXTRA_SUBJECT, title);
        }
        Intent chooser = null;
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            // requestCode parameter is not used. Providing 0
            PendingIntent pi = PendingIntent.getBroadcast(getContext(), 0, new Intent(Intent.EXTRA_CHOSEN_COMPONENT), PendingIntent.FLAG_UPDATE_CURRENT);
            chooser = Intent.createChooser(intent, dialogTitle, pi.getIntentSender());
            chosenComponent = null;
        } else {
            chooser = Intent.createChooser(intent, dialogTitle);
        }
        chooser.addCategory(Intent.CATEGORY_DEFAULT);
        stopped = false;
        isPresenting = true;
        startActivityForResult(call, chooser, "activityResult");
    } else {
        call.reject("Can't share while sharing is in progress");
    }
}
Also used : PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Uri(android.net.Uri) File(java.io.File) PluginMethod(com.getcapacitor.PluginMethod)

Example 89 with PluginMethod

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

the class StoragePlugin method migrate.

@PluginMethod
public void migrate(PluginCall call) {
    List<String> migrated = new ArrayList<>();
    List<String> existing = new ArrayList<>();
    Storage oldStorage = new Storage(getContext(), StorageConfiguration.DEFAULTS);
    for (String key : oldStorage.keys()) {
        String value = oldStorage.get(key);
        String currentValue = storage.get(key);
        if (currentValue == null) {
            storage.set(key, value);
            migrated.add(key);
        } else {
            existing.add(key);
        }
    }
    JSObject ret = new JSObject();
    ret.put("migrated", new JSArray(migrated));
    ret.put("existing", new JSArray(existing));
    call.resolve(ret);
}
Also used : ArrayList(java.util.ArrayList) JSArray(com.getcapacitor.JSArray) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 90 with PluginMethod

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

the class StoragePlugin method keys.

@PluginMethod
public void keys(PluginCall call) {
    Set<String> keySet = storage.keys();
    String[] keys = keySet.toArray(new String[0]);
    JSObject ret = new JSObject();
    try {
        ret.put("keys", new JSArray(keys));
    } catch (JSONException ex) {
        call.reject("Unable to serialize response.", ex);
        return;
    }
    call.resolve(ret);
}
Also used : JSArray(com.getcapacitor.JSArray) JSObject(com.getcapacitor.JSObject) JSONException(org.json.JSONException) 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