Java Code Examples for com.getcapacitor.PluginCall#success()

The following examples show how to use com.getcapacitor.PluginCall#success() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PushNotifications.java    From OsmGo with MIT License 6 votes vote down vote up
@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();
  }
}
 
Example 2
Source File: App.java    From OsmGo with MIT License 6 votes vote down vote up
@PluginMethod()
public void canOpenUrl(PluginCall call) {
  String url = call.getString("url");
  if (url == null) {
    call.error("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.success(ret);
    return;
  } catch(PackageManager.NameNotFoundException e) {
    Log.e(getLogTag(), "Package name '"+url+"' not found!");
  }

  ret.put("value", false);
  call.success(ret);
}
 
Example 3
Source File: Filesystem.java    From OsmGo with MIT License 6 votes vote down vote up
@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();
    }
  }
}
 
Example 4
Source File: Filesystem.java    From OsmGo with MIT License 6 votes vote down vote up
@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);
  }
}
 
Example 5
Source File: AdMob.java    From capacitor-admob with MIT License 6 votes vote down vote up
@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);
    }
}
 
Example 6
Source File: Haptics.java    From OsmGo with MIT License 6 votes vote down vote up
@PluginMethod()
@SuppressWarnings("MissingPermission")
public void vibrate(PluginCall call) {
  Context c = this.getContext();
  int duration = call.getInt("duration", 300);

  if(!hasPermission(Manifest.permission.VIBRATE)) {
    call.error("Can't vibrate: Missing VIBRATE permission in AndroidManifest.xml");
    return;
  }

  if (Build.VERSION.SDK_INT >= 26) {
    ((Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(duration, VibrationEffect.DEFAULT_AMPLITUDE));
  } else {
    vibratePre26(duration);
  }

  call.success();
}
 
Example 7
Source File: Filesystem.java    From OsmGo with MIT License 6 votes vote down vote up
@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");
    }
  }
}
 
Example 8
Source File: AdMob.java    From capacitor-admob with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example 9
Source File: WebView.java    From OsmGo with MIT License 5 votes vote down vote up
@PluginMethod()
public void getServerBasePath(PluginCall call) {
  String path = bridge.getServerBasePath();
  JSObject ret = new JSObject();
  ret.put("path", path);
  call.success(ret);
}
 
Example 10
Source File: PushNotifications.java    From OsmGo with MIT License 5 votes vote down vote up
@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();
  }
}
 
Example 11
Source File: Browser.java    From OsmGo with MIT License 5 votes vote down vote up
@PluginMethod()
public void open(PluginCall call) {
  String url = call.getString("url");
  String toolbarColor = call.getString("toolbarColor");

  if (url == null) {
    call.error("Must provide a URL to open");
    return;
  }

  if (url.isEmpty()) {
    call.error("URL must not be empty");
    return;
  }

  CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(getCustomTabsSession());

  builder.addDefaultShareMenuItem();

  if (toolbarColor != null) {
    try {
      builder.setToolbarColor(Color.parseColor(toolbarColor));
    } catch (IllegalArgumentException ex) {
      Log.e(getLogTag(), "Invalid color provided for toolbarColor. Using default");
    }
  }

  CustomTabsIntent tabsIntent = builder.build();
  tabsIntent.intent.putExtra(Intent.EXTRA_REFERRER,
      Uri.parse(Intent.URI_ANDROID_APP_SCHEME + "//" + getContext().getPackageName()));
  tabsIntent.launchUrl(getContext(), Uri.parse(url));
  call.success();
}
 
Example 12
Source File: Geolocation.java    From OsmGo with MIT License 5 votes vote down vote up
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));
  }
}
 
Example 13
Source File: AdMob.java    From capacitor-admob with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example 14
Source File: AdMob.java    From capacitor-admob with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example 15
Source File: WebView.java    From OsmGo with MIT License 5 votes vote down vote up
@PluginMethod()
public void persistServerBasePath(PluginCall call) {
  String path = bridge.getServerBasePath();
  SharedPreferences prefs = getContext().getSharedPreferences(WEBVIEW_PREFS_NAME, Activity.MODE_PRIVATE);
  SharedPreferences.Editor editor = prefs.edit();
  editor.putString(CAP_SERVER_PATH, path);
  editor.apply();
  call.success();
}
 
Example 16
Source File: BackgroundTask.java    From OsmGo with MIT License 5 votes vote down vote up
@PluginMethod()
public void finish(PluginCall call) {
  String taskId = call.getString("taskId");
  if (taskId == null) {
    call.error("Must provide taskId");
    return;
  }

  call.success();
}
 
Example 17
Source File: CapacitorFirebaseAuth.java    From capacitor-firebase-auth with MIT License 5 votes vote down vote up
@PluginMethod()
public void signOut(PluginCall call) {
    // sing out from providers
    for (ProviderHandler providerHandler : this.providerHandlers.values()) {
        providerHandler.signOut();
    }

    // sign out from firebase
    FirebaseUser currentUser = this.firebaseAuth.getCurrentUser();
    if (currentUser != null) {
        this.firebaseAuth.signOut();
    }

    call.success();
}
 
Example 18
Source File: LocalNotifications.java    From OsmGo with MIT License 4 votes vote down vote up
@PluginMethod()
public void getPending(PluginCall call) {
  List<String> ids = notificationStorage.getSavedNotificationIds();
  JSObject result = LocalNotification.buildLocalNotificationPendingList(ids);
  call.success(result);
}
 
Example 19
Source File: Device.java    From OsmGo with MIT License 4 votes vote down vote up
@PluginMethod()
public void getLanguageCode(PluginCall call) {
  JSObject ret = new JSObject();
  ret.put("value", Locale.getDefault().getLanguage());
  call.success(ret);
}
 
Example 20
Source File: PushNotifications.java    From OsmGo with MIT License 4 votes vote down vote up
@PluginMethod()
public void removeAllDeliveredNotifications(PluginCall call) {
  notificationManager.cancelAll();
  call.success();
}