com.getcapacitor.PluginCall.success()

Here are the examples of the java api com.getcapacitor.PluginCall.success() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

116 Examples 7

19 Source : PermissionPlugin.java
with MIT License
from UniStudents

@PluginMethod()
public void isXiaomi(PluginCall call) {
    try {
        String manufacturer = android.os.Build.MANUFACTURER;
        JSObject ret = new JSObject();
        ret.put("isXiaomi", "xiaomi".equalsIgnoreCase(manufacturer));
        call.success(ret);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

19 Source : FCMPlugin.java
with MIT License
from UniStudents

@PluginMethod()
public void subscribeTo(final PluginCall call) {
    final String topicName = call.getString("topic");
    FirebaseMessaging.getInstance().subscribeToTopic(topicName).addOnSuccessListener(aVoid -> {
        JSObject ret = new JSObject();
        ret.put("message", "Subscribed to topic " + topicName);
        call.success(ret);
    }).addOnFailureListener(e -> call.error("Cant subscribe to topic" + topicName, e));
}

19 Source : FCMPlugin.java
with MIT License
from UniStudents

@PluginMethod()
public void unsubscribeFrom(final PluginCall call) {
    final String topicName = call.getString("topic");
    FirebaseMessaging.getInstance().unsubscribeFromTopic(topicName).addOnSuccessListener(aVoid -> {
        JSObject ret = new JSObject();
        ret.put("message", "Unsubscribed from topic " + topicName);
        call.success(ret);
    }).addOnFailureListener(e -> call.error("Cant unsubscribe from topic" + topicName, e));
}

19 Source : FCMPlugin.java
with MIT License
from UniStudents

@PluginMethod()
public void deleteInstance(final PluginCall call) {
    Runnable r = () -> {
        try {
            FirebaseInstanceId.getInstance().deleteInstanceId();
            call.success();
        } catch (IOException e) {
            e.printStackTrace();
            call.error("Cant delete Firebase Instance ID", e);
        }
    };
    new Thread(r).start();
}

19 Source : FCMPlugin.java
with MIT License
from UniStudents

@PluginMethod()
public void getToken(final PluginCall call) {
    FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(getActivity(), instanceIdResult -> {
        JSObject data = new JSObject();
        data.put("token", instanceIdResult.getToken());
        call.success(data);
    });
    FirebaseInstanceId.getInstance().getInstanceId().addOnFailureListener(e -> call.error("Failed to get instance FirebaseID", e));
}

19 Source : AdMob.java
with MIT License
from rahadur

// Destroy a RewardVideoAd
@PluginMethod()
public void stopRewardedVideo(PluginCall call) {
    try {
        getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                mRewardedVideoAd.destroy(getContext());
            }
        });
        call.success(new JSObject().put("value", true));
    } catch (Exception ex) {
        call.error(ex.getLocalizedMessage(), ex);
    }
}

19 Source : AdMob.java
with MIT License
from rahadur

// Pause a RewardVideoAd
@PluginMethod()
public void pauseRewardedVideo(PluginCall call) {
    try {
        getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                mRewardedVideoAd.pause(getContext());
            }
        });
        call.success(new JSObject().put("value", true));
    } catch (Exception ex) {
        call.error(ex.getLocalizedMessage(), ex);
    }
}

19 Source : AdMob.java
with MIT License
from rahadur

// Initialize AdMob with appId
@PluginMethod()
public void initialize(PluginCall call) {
    /* Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 */
    String appId = call.getString("appId", "ca-app-pub-3940256099942544~3347511713");
    try {
        MobileAds.initialize(this.getContext(), appId);
        mViewGroup = (ViewGroup) ((ViewGroup) getActivity().findViewById(android.R.id.content)).getChildAt(0);
        call.success();
    } catch (Exception ex) {
        call.error(ex.getLocalizedMessage(), ex);
    }
}

19 Source : AdMob.java
with MIT License
from rahadur

// Destroy the banner, remove it from screen.
@PluginMethod()
public void removeBanner(PluginCall call) {
    try {
        if (mAdView != null) {
            getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (mAdView != null) {
                        mViewGroup.removeView(mAdViewLayout);
                        mAdViewLayout.removeView(mAdView);
                        mAdView.destroy();
                        mAdView = null;
                        Log.d(getLogTag(), "Banner AD Removed");
                    }
                }
            });
        }
        call.success(new JSObject().put("value", true));
    } catch (Exception ex) {
        call.error(ex.getLocalizedMessage(), ex);
    }
}

19 Source : AdMob.java
with MIT License
from rahadur

// Resume a RewardVideoAd
@PluginMethod()
public void resumeRewardedVideo(PluginCall call) {
    try {
        getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                mRewardedVideoAd.resume(getContext());
            }
        });
        call.success(new JSObject().put("value", true));
    } catch (Exception ex) {
        call.error(ex.getLocalizedMessage(), ex);
    }
}

19 Source : AdMob.java
with MIT License
from rahadur

// Resume the banner, show it after hide
@PluginMethod()
public void resumeBanner(PluginCall call) {
    try {
        getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                if (mAdViewLayout != null && mAdView != null) {
                    mAdViewLayout.setVisibility(View.VISIBLE);
                    mAdView.resume();
                    Log.d(getLogTag(), "Banner AD Resumed");
                }
            }
        });
        call.success(new JSObject().put("value", true));
    } catch (Exception ex) {
        call.error(ex.getLocalizedMessage(), ex);
    }
}

19 Source : AdMob.java
with MIT License
from rahadur

// Hide the banner, remove it from screen, but can show it later
@PluginMethod()
public void hideBanner(PluginCall call) {
    try {
        getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                if (mAdViewLayout != null) {
                    mAdViewLayout.setVisibility(View.GONE);
                    mAdView.pause();
                }
            }
        });
        call.success(new JSObject().put("value", true));
    } catch (Exception ex) {
        call.error(ex.getLocalizedMessage(), ex);
    }
}

19 Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau

@PluginMethod
public void pause(final PluginCall call) {
    saveCall(call);
    JSObject ret = new JSObject();
    ret.put("method", "pause");
    String playerId = call.getString("playerId");
    if (playerId == null) {
        ret.put("result", false);
        ret.put("message", "Must provide a PlayerId");
        call.success(ret);
        return;
    }
    if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
        bridge.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                fsFragment.pause();
                JSObject data = new JSObject();
                data.put("result", true);
                data.put("method", "pause");
                data.put("value", true);
                call.success(data);
            }
        });
    } else {
        ret.put("result", false);
        ret.put("message", "player is not defined");
        call.success(ret);
    }
}

19 Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau

@PluginMethod
public void setMuted(final PluginCall call) {
    saveCall(call);
    JSObject ret = new JSObject();
    ret.put("method", "setMuted");
    String playerId = call.getString("playerId");
    if (playerId == null) {
        ret.put("result", false);
        ret.put("message", "Must provide a PlayerId");
        call.success(ret);
        return;
    }
    Boolean value = call.getBoolean("muted");
    if (value == null) {
        ret.put("result", true);
        ret.put("message", "Must provide a boolean true/false");
        call.success(ret);
        return;
    }
    final boolean bValue = value;
    if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
        bridge.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                fsFragment.setMuted(bValue);
                JSObject ret = new JSObject();
                ret.put("result", true);
                ret.put("method", "setMuted");
                ret.put("value", bValue);
                call.success(ret);
            }
        });
    } else {
        ret.put("result", false);
        ret.put("message", "player is not defined");
        call.success(ret);
    }
}

19 Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau

@PluginMethod
public void echo(PluginCall call) {
    String value = call.getString("value");
    JSObject ret = new JSObject();
    ret.put("value", value);
    call.success(ret);
}

19 Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau

@PluginMethod
public void setVolume(final PluginCall call) {
    saveCall(call);
    JSObject ret = new JSObject();
    ret.put("method", "setVolume");
    String playerId = call.getString("playerId");
    if (playerId == null) {
        ret.put("result", false);
        ret.put("message", "Must provide a PlayerId");
        call.success(ret);
        return;
    }
    String value = call.getString("volume");
    if (value == null) {
        ret.put("result", false);
        ret.put("method", "setVolume");
        ret.put("message", "Must provide a volume value");
        call.success(ret);
        return;
    }
    final Float volume = Float.valueOf(value.trim());
    if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
        bridge.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                fsFragment.setVolume(volume);
                JSObject ret = new JSObject();
                ret.put("result", true);
                ret.put("method", "setVolume");
                ret.put("value", volume);
                call.success(ret);
            }
        });
    } else {
        ret.put("result", false);
        ret.put("message", "player is not defined");
        call.success(ret);
    }
}

19 Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau

@PluginMethod
public void isPlaying(final PluginCall call) {
    saveCall(call);
    JSObject ret = new JSObject();
    ret.put("method", "isPlaying");
    String playerId = call.getString("playerId");
    if (playerId == null) {
        ret.put("result", false);
        ret.put("message", "Must provide a PlayerId");
        call.success(ret);
        return;
    }
    if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
        bridge.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                boolean playing = fsFragment.isPlaying();
                JSObject data = new JSObject();
                data.put("result", true);
                data.put("method", "isPlaying");
                data.put("value", playing);
                call.success(data);
            }
        });
    } else {
        ret.put("result", false);
        ret.put("message", "player is not defined");
        call.success(ret);
    }
}

19 Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau

@PluginMethod
public void play(final PluginCall call) {
    saveCall(call);
    JSObject ret = new JSObject();
    ret.put("method", "play");
    String playerId = call.getString("playerId");
    if (playerId == null) {
        ret.put("result", false);
        ret.put("message", "Must provide a PlayerId");
        call.success(ret);
        return;
    }
    if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
        bridge.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                fsFragment.play();
                boolean playing = fsFragment.isPlaying();
                JSObject data = new JSObject();
                data.put("result", true);
                data.put("method", "play");
                data.put("value", true);
                call.success(data);
            }
        });
    } else {
        ret.put("result", false);
        ret.put("message", "player is not defined");
        call.success(ret);
    }
}

19 Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau

@PluginMethod
public void getVolume(final PluginCall call) {
    saveCall(call);
    JSObject ret = new JSObject();
    ret.put("method", "getVolume");
    String playerId = call.getString("playerId");
    if (playerId == null) {
        ret.put("result", false);
        ret.put("message", "Must provide a PlayerId");
        call.success(ret);
        return;
    }
    if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
        bridge.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Float volume = fsFragment.getVolume();
                JSObject ret = new JSObject();
                ret.put("result", true);
                ret.put("method", "getVolume");
                ret.put("value", volume);
                call.success(ret);
            }
        });
    } else {
        ret.put("result", false);
        ret.put("message", "player is not defined");
        call.success(ret);
    }
}

19 Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau

@PluginMethod
public void getDuration(final PluginCall call) {
    saveCall(call);
    JSObject ret = new JSObject();
    ret.put("method", "getDuration");
    String playerId = call.getString("playerId");
    if (playerId == null) {
        ret.put("result", false);
        ret.put("message", "Must provide a PlayerId");
        call.success(ret);
        return;
    }
    if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
        bridge.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                JSObject ret = new JSObject();
                ret.put("method", "getDuration");
                int duration = fsFragment.getDuration();
                ret.put("result", true);
                ret.put("value", duration);
                call.success(ret);
            }
        });
    } else {
        ret.put("result", false);
        ret.put("message", "player is not defined");
        call.success(ret);
    }
}

19 Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau

@PluginMethod
public void getCurrentTime(final PluginCall call) {
    saveCall(call);
    JSObject ret = new JSObject();
    ret.put("method", "getCurrentTime");
    String playerId = call.getString("playerId");
    if (playerId == null) {
        ret.put("result", false);
        ret.put("message", "Must provide a PlayerId");
        call.success(ret);
        return;
    }
    if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
        bridge.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                JSObject ret = new JSObject();
                ret.put("method", "getCurrentTime");
                int curTime = fsFragment.getCurrentTime();
                ret.put("result", true);
                ret.put("value", curTime);
                call.success(ret);
            }
        });
    } else {
        ret.put("result", false);
        ret.put("message", "player is not defined");
        call.success(ret);
    }
}

19 Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau

@PluginMethod
public void getMuted(final PluginCall call) {
    saveCall(call);
    JSObject ret = new JSObject();
    ret.put("method", "getMuted");
    String playerId = call.getString("playerId");
    if (playerId == null) {
        ret.put("result", false);
        ret.put("message", "Must provide a PlayerId");
        call.success(ret);
        return;
    }
    if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
        bridge.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                boolean value = fsFragment.getMuted();
                JSObject ret = new JSObject();
                ret.put("result", true);
                ret.put("method", "getMuted");
                ret.put("value", value);
                call.success(ret);
            }
        });
    } else {
        ret.put("result", false);
        ret.put("message", "player is not defined");
        call.success(ret);
    }
}

19 Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau

@PluginMethod
public void setCurrentTime(final PluginCall call) {
    saveCall(call);
    JSObject ret = new JSObject();
    ret.put("method", "setCurrentTime");
    String playerId = call.getString("playerId");
    if (playerId == null) {
        ret.put("result", false);
        ret.put("message", "Must provide a PlayerId");
        call.success(ret);
        return;
    }
    Double value = call.getDouble("seektime");
    if (value == null) {
        ret.put("result", false);
        ret.put("message", "Must provide a time in second");
        call.success(ret);
        return;
    }
    final int cTime = (int) Math.round(value);
    if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
        bridge.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                fsFragment.setCurrentTime(cTime);
                JSObject ret = new JSObject();
                ret.put("result", true);
                ret.put("method", "setCurrentTime");
                ret.put("value", cTime);
                call.success(ret);
            }
        });
    } else {
        ret.put("result", false);
        ret.put("message", "player is not defined");
        call.success(ret);
    }
}

19 Source : CapacitorGoogleMaps.java
with MIT License
from hemangsk

@PluginMethod()
public void setMapType(PluginCall call) {
    String specifiedMapType = call.getString("type", "normal");
    Integer mapType;
    switch(specifiedMapType) {
        case "hybrid":
            mapType = GoogleMap.MAP_TYPE_HYBRID;
            break;
        case "satellite":
            mapType = GoogleMap.MAP_TYPE_SATELLITE;
            break;
        case "terrain":
            mapType = GoogleMap.MAP_TYPE_TERRAIN;
            break;
        case "none":
            mapType = GoogleMap.MAP_TYPE_NONE;
            break;
        default:
            mapType = GoogleMap.MAP_TYPE_NORMAL;
    }
    final Integer selectedMapType = mapType;
    getBridge().getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            googleMap.setMapType(selectedMapType);
        }
    });
    call.success();
}

19 Source : CapacitorGoogleMaps.java
with MIT License
from hemangsk

@PluginMethod()
public void clear(PluginCall call) {
    getBridge().executeOnMainThread(new Runnable() {

        @Override
        public void run() {
            googleMap.clear();
        }
    });
    call.success();
}

19 Source : CapacitorGoogleMaps.java
with MIT License
from hemangsk

@PluginMethod()
public void setTrafficEnabled(PluginCall call) {
    final Boolean trafficEnabled = call.getBoolean("enabled", false);
    getBridge().executeOnMainThread(new Runnable() {

        @Override
        public void run() {
            googleMap.setTrafficEnabled(trafficEnabled);
        }
    });
    call.success();
}

19 Source : CapacitorGoogleMaps.java
with MIT License
from hemangsk

@PluginMethod()
public void padding(PluginCall call) {
    final Integer top = call.getInt("top", 0);
    final Integer left = call.getInt("left", 0);
    final Integer bottom = call.getInt("bottom", 0);
    final Integer right = call.getInt("right", 0);
    getBridge().executeOnMainThread(new Runnable() {

        @Override
        public void run() {
            googleMap.setPadding(left, top, right, bottom);
        }
    });
    call.success();
}

19 Source : CapacitorGoogleMaps.java
with MIT License
from hemangsk

@PluginMethod()
public void create(PluginCall call) {
    final Integer width = call.getInt("width", DEFAULT_WIDTH);
    final Integer height = call.getInt("height", DEFAULT_HEIGHT);
    final Integer x = call.getInt("x", 0);
    final Integer y = call.getInt("y", 0);
    final Float zoom = call.getFloat("zoom", DEFAULT_ZOOM);
    final Double lareplacedude = call.getDouble("lareplacedude");
    final Double longitude = call.getDouble("longitude");
    final boolean liteMode = call.getBoolean("enabled", false);
    final CapacitorGoogleMaps ctx = this;
    getBridge().getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            LatLng latLng = new LatLng(lareplacedude, longitude);
            CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng).zoom(zoom).build();
            GoogleMapOptions googleMapOptions = new GoogleMapOptions();
            googleMapOptions.camera(cameraPosition);
            googleMapOptions.liteMode(liteMode);
            FrameLayout mapViewParent = new FrameLayout(getBridge().getContext());
            mapViewParentId = View.generateViewId();
            mapViewParent.setId(mapViewParentId);
            mapView = new MapView(getBridge().getContext(), googleMapOptions);
            FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(getScaledPixels(width), getScaledPixels(height));
            lp.topMargin = getScaledPixels(y);
            lp.leftMargin = getScaledPixels(x);
            mapView.setLayoutParams(lp);
            mapViewParent.addView(mapView);
            ((ViewGroup) getBridge().getWebView().getParent()).addView(mapViewParent);
            mapView.onCreate(null);
            mapView.getMapAsync(ctx);
        }
    });
    call.success();
}

19 Source : CapacitorGoogleMaps.java
with MIT License
from hemangsk

@PluginMethod()
public void initialize(PluginCall call) {
    /*
         *  TODO: Check location permissions and API key
         */
    call.success();
}

19 Source : CapacitorGoogleMaps.java
with MIT License
from hemangsk

@PluginMethod()
public void setIndoorEnabled(PluginCall call) {
    final Boolean indoorEnabled = call.getBoolean("enabled", false);
    getBridge().executeOnMainThread(new Runnable() {

        @Override
        public void run() {
            googleMap.setIndoorEnabled(indoorEnabled);
        }
    });
    call.success();
}

19 Source : WebView.java
with MIT License
from DoFabien

@PluginMethod()
public void setServerBasePath(PluginCall call) {
    String path = call.getString("path");
    bridge.setServerBasePath(path);
    call.success();
}

19 Source : WebView.java
with MIT License
from DoFabien

@PluginMethod()
public void getServerBasePath(PluginCall call) {
    String path = bridge.getServerBasePath();
    JSObject ret = new JSObject();
    ret.put("path", path);
    call.success(ret);
}

19 Source : Toast.java
with MIT License
from DoFabien

@PluginMethod()
public void show(PluginCall call) {
    CharSequence text = call.getString("text");
    if (text == null) {
        call.error("Must provide text");
        return;
    }
    String durationType = call.getString("durationType", "short");
    int duration = android.widget.Toast.LENGTH_SHORT;
    if ("long".equals(durationType)) {
        duration = android.widget.Toast.LENGTH_LONG;
    }
    android.widget.Toast toast = android.widget.Toast.makeText(getContext(), text, duration);
    toast.show();
    call.success();
}

19 Source : SplashScreen.java
with MIT License
from DoFabien

@PluginMethod()
public void hide(PluginCall call) {
    int fadeDuration = call.getInt("fadeOutDuration", Splash.DEFAULT_FADE_OUT_DURATION);
    Splash.hide(getContext(), fadeDuration);
    call.success();
}

19 Source : PushNotifications.java
with MIT License
from DoFabien

@PluginMethod()
public void listChannels(PluginCall call) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        List<NotificationChannel> notificationChannels = notificationManager.getNotificationChannels();
        JSArray channels = new JSArray();
        for (NotificationChannel notificationChannel : notificationChannels) {
            JSObject channel = new JSObject();
            channel.put(CHANNEL_ID, notificationChannel.getId());
            channel.put(CHANNEL_NAME, notificationChannel.getName());
            channel.put(CHANNEL_DESCRIPTION, notificationChannel.getDescription());
            channel.put(CHANNEL_IMPORTANCE, notificationChannel.getImportance());
            channel.put(CHANNEL_VISIBILITY, notificationChannel.getLockscreenVisibility());
            Log.d(getLogTag(), "visibility " + notificationChannel.getLockscreenVisibility());
            Log.d(getLogTag(), "importance " + notificationChannel.getImportance());
            channels.put(channel);
        }
        JSObject result = new JSObject();
        result.put("channels", channels);
        call.success(result);
    } else {
        call.unavailable();
    }
}

19 Source : PushNotifications.java
with MIT License
from DoFabien

@PluginMethod()
public void createChannel(PluginCall call) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        JSObject channel = new JSObject();
        channel.put(CHANNEL_ID, call.getString(CHANNEL_ID));
        channel.put(CHANNEL_NAME, call.getString(CHANNEL_NAME));
        channel.put(CHANNEL_DESCRIPTION, call.getString(CHANNEL_DESCRIPTION, ""));
        channel.put(CHANNEL_VISIBILITY, call.getInt(CHANNEL_VISIBILITY, NotificationCompat.VISIBILITY_PUBLIC));
        channel.put(CHANNEL_IMPORTANCE, call.getInt(CHANNEL_IMPORTANCE));
        createChannel(channel);
        call.success();
    } else {
        call.unavailable();
    }
}

19 Source : PushNotifications.java
with MIT License
from DoFabien

@PluginMethod()
public void removeAllDeliveredNotifications(PluginCall call) {
    notificationManager.cancelAll();
    call.success();
}

19 Source : PushNotifications.java
with MIT License
from DoFabien

@PluginMethod()
public void deleteChannel(PluginCall call) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        String channelId = call.getString("id");
        notificationManager.deleteNotificationChannel(channelId);
        call.success();
    } else {
        call.unavailable();
    }
}

19 Source : LocalNotificationManager.java
with MIT License
from DoFabien

public void cancel(PluginCall call) {
    List<Integer> notificationsToCancel = LocalNotification.getLocalNotificationPendingList(call);
    if (notificationsToCancel != null) {
        for (Integer id : notificationsToCancel) {
            dismissVisibleNotification(id);
            cancelTimerForNotification(id);
            storage.deleteNotification(Integer.toString(id));
        }
    }
    call.success();
}

19 Source : LocalNotifications.java
with MIT License
from DoFabien

/**
 * Schedule a notification call from JavaScript
 * Creates local notification in system.
 */
@PluginMethod()
public void schedule(PluginCall call) {
    List<LocalNotification> localNotifications = LocalNotification.buildNotificationList(call);
    if (localNotifications == null) {
        return;
    }
    JSONArray ids = manager.schedule(call, localNotifications);
    notificationStorage.appendNotificationIds(localNotifications);
    call.success(new JSObject().put("ids", ids));
}

19 Source : LocalNotifications.java
with MIT License
from DoFabien

@PluginMethod()
public void getPending(PluginCall call) {
    List<String> ids = notificationStorage.getSavedNotificationIds();
    JSObject result = LocalNotification.buildLocalNotificationPendingList(ids);
    call.success(result);
}

19 Source : LocalNotifications.java
with MIT License
from DoFabien

@PluginMethod()
public void areEnabled(PluginCall call) {
    JSObject data = new JSObject();
    data.put("value", manager.areNotificationsEnabled());
    call.success(data);
}

19 Source : Geolocation.java
with MIT License
from DoFabien

@SuppressWarnings("MissingPermission")
@PluginMethod()
public void clearWatch(PluginCall call) {
    String callbackId = call.getString("id");
    if (callbackId != null) {
        PluginCall removed = watchingCalls.remove(callbackId);
        if (removed != null) {
            removed.release(bridge);
        }
    }
    if (watchingCalls.size() == 0) {
        locationManager.removeUpdates(locationListener);
    }
    call.success();
}

19 Source : Geolocation.java
with MIT License
from DoFabien

private void sendLocation(PluginCall call) {
    String provider = getBestProviderForCall(call);
    Location lastLocation = getBestLocation(provider);
    if (lastLocation == null) {
        call.error("location unavailable");
    } else {
        call.success(getJSObjectForLocation(lastLocation));
    }
}

19 Source : Filesystem.java
with MIT License
from DoFabien

@PluginMethod()
public void deleteFile(PluginCall call) {
    saveCall(call);
    String file = call.getString("path");
    String directory = getDirectoryParameter(call);
    File fileObject = getFileObject(file, directory);
    if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_DELETE_FILE_PERMISSIONS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        if (!fileObject.exists()) {
            call.error("File does not exist");
            return;
        }
        boolean deleted = fileObject.delete();
        if (deleted == false) {
            call.error("Unable to delete file");
        } else {
            call.success();
        }
    }
}

19 Source : Filesystem.java
with MIT License
from DoFabien

@PluginMethod()
public void mkdir(PluginCall call) {
    saveCall(call);
    String path = call.getString("path");
    String directory = getDirectoryParameter(call);
    boolean intermediate = call.getBoolean("createIntermediateDirectories", false).booleanValue();
    File fileObject = getFileObject(path, directory);
    if (fileObject.exists()) {
        call.error("Directory exists");
        return;
    }
    if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_WRITE_FOLDER_PERMISSIONS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        boolean created = false;
        if (intermediate) {
            created = fileObject.mkdirs();
        } else {
            created = fileObject.mkdir();
        }
        if (created == false) {
            call.error("Unable to create directory, unknown reason");
        } else {
            call.success();
        }
    }
}

19 Source : Filesystem.java
with MIT License
from DoFabien

@PluginMethod()
public void stat(PluginCall call) {
    saveCall(call);
    String path = call.getString("path");
    String directory = getDirectoryParameter(call);
    File fileObject = getFileObject(path, directory);
    if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_STAT_PERMISSIONS, Manifest.permission.READ_EXTERNAL_STORAGE)) {
        if (!fileObject.exists()) {
            call.error("File does not exist");
            return;
        }
        JSObject data = new JSObject();
        data.put("type", fileObject.isDirectory() ? "directory" : "file");
        data.put("size", fileObject.length());
        data.put("ctime", null);
        data.put("mtime", fileObject.lastModified());
        data.put("uri", Uri.fromFile(fileObject).toString());
        call.success(data);
    }
}

19 Source : Filesystem.java
with MIT License
from DoFabien

private void _copy(PluginCall call, boolean doRename) {
    saveCall(call);
    String from = call.getString("from");
    String to = call.getString("to");
    String directory = call.getString("directory");
    String toDirectory = call.getString("toDirectory");
    if (toDirectory == null) {
        toDirectory = directory;
    }
    if (from == null || from.isEmpty() || to == null || to.isEmpty()) {
        call.error("Both to and from must be provided");
        return;
    }
    File fromObject = getFileObject(from, directory);
    File toObject = getFileObject(to, toDirectory);
    replacedert fromObject != null;
    replacedert toObject != null;
    if (toObject.equals(fromObject)) {
        call.success();
        return;
    }
    if (!fromObject.exists()) {
        call.error("The source object does not exist");
        return;
    }
    if (toObject.getParentFile().isFile()) {
        call.error("The parent object of the destination is a file");
        return;
    }
    if (!toObject.getParentFile().exists()) {
        call.error("The parent object of the destination does not exist");
        return;
    }
    if (isPublicDirectory(directory) || isPublicDirectory(toDirectory)) {
        if (doRename) {
            if (!isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_RENAME_PERMISSIONS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                return;
            }
        } else {
            if (!isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_COPY_PERMISSIONS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                return;
            }
        }
    }
    if (toObject.isDirectory()) {
        call.error("Cannot overwrite a directory");
        return;
    }
    toObject.delete();
    replacedert fromObject != null;
    boolean modified = false;
    if (doRename) {
        modified = fromObject.renameTo(toObject);
    } else {
        try {
            copyRecursively(fromObject, toObject);
            modified = true;
        } catch (IOException ignored) {
        }
    }
    if (!modified) {
        call.error("Unable to perform action, unknown reason");
        return;
    }
    call.success();
}

19 Source : Filesystem.java
with MIT License
from DoFabien

@PluginMethod()
public void getUri(PluginCall call) {
    saveCall(call);
    String path = call.getString("path");
    String directory = getDirectoryParameter(call);
    File fileObject = getFileObject(path, directory);
    if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_URI_PERMISSIONS, Manifest.permission.READ_EXTERNAL_STORAGE)) {
        JSObject data = new JSObject();
        data.put("uri", Uri.fromFile(fileObject).toString());
        call.success(data);
    }
}

19 Source : Filesystem.java
with MIT License
from DoFabien

@PluginMethod()
public void readdir(PluginCall call) {
    saveCall(call);
    String path = call.getString("path");
    String directory = getDirectoryParameter(call);
    File fileObject = getFileObject(path, directory);
    if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_READ_FOLDER_PERMISSIONS, Manifest.permission.READ_EXTERNAL_STORAGE)) {
        if (fileObject != null && fileObject.exists()) {
            String[] files = fileObject.list();
            JSObject ret = new JSObject();
            ret.put("files", JSArray.from(files));
            call.success(ret);
        } else {
            call.error("Directory does not exist");
        }
    }
}

See More Examples