Java Code Examples for io.flutter.plugin.common.MethodCall#argument()

The following examples show how to use io.flutter.plugin.common.MethodCall#argument() . 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: TencentImPlugin.java    From FlutterTencentImPlugin with Apache License 2.0 6 votes vote down vote up
/**
 * 腾讯云 获取自己的资料
 *
 * @param methodCall 方法调用对象
 * @param result     返回结果对象
 */
private void getSelfProfile(MethodCall methodCall, final Result result) {
    // 强制走后台拉取
    Boolean forceUpdate = methodCall.argument("forceUpdate");
    if (forceUpdate != null && forceUpdate) {
        TIMFriendshipManager.getInstance().getSelfProfile(new ValueCallBack<TIMUserProfile>(result));
    } else {
        // 先获取本地,再获取服务器
        TIMUserProfile data = TIMFriendshipManager.getInstance().querySelfProfile();
        if (data == null) {
            TIMFriendshipManager.getInstance().getSelfProfile(new ValueCallBack<TIMUserProfile>(result));
        } else {
            result.success(JsonUtil.toJSONString(data));
        }
    }
}
 
Example 2
Source File: TencentImPlugin.java    From FlutterTencentImPlugin with Apache License 2.0 6 votes vote down vote up
/**
 * 腾讯云 拒绝申请
 *
 * @param methodCall 方法调用对象
 * @param result     返回结果对象
 */
private void groupPendencyRefuse(MethodCall methodCall, final Result result) {
    // 理由
    final String msg = methodCall.argument("msg");
    // 群ID
    final String groupId = this.getParam(methodCall, result, "groupId");
    // 申请人ID
    final String identifier = this.getParam(methodCall, result, "identifier");
    // 申请时间
    final long addTime = Long.parseLong(this.getParam(methodCall, result, "addTime").toString());

    TIMGroupManager.getInstance().getGroupPendencyList(new TIMGroupPendencyGetParam(), new ValueCallBack<TIMGroupPendencyListGetSucc>(result) {
        @Override
        public void onSuccess(TIMGroupPendencyListGetSucc timGroupPendencyListGetSucc) {
            List<TIMGroupPendencyItem> data = timGroupPendencyListGetSucc.getPendencies();
            if (data != null) {
                for (TIMGroupPendencyItem datum : data) {
                    if (datum.getGroupId().equals(groupId) && datum.getIdentifer().equals(identifier) && datum.getAddTime() == addTime) {
                        datum.refuse(msg, new VoidCallBack(result));
                        break;
                    }
                }
            }
        }
    });
}
 
Example 3
Source File: SmsSender.java    From flutter_sms with MIT License 6 votes vote down vote up
@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
    if (call.method.equals("sendSMS")) {
        String address = call.argument("address").toString();
        String body = call.argument("body").toString();
        int sentId = call.argument("sentId");
        Integer subId = call.argument("subId");
        if (address == null) {
            result.error("#02", "missing argument 'address'", null);
        } else if (body == null) {
            result.error("#02", "missing argument 'body'", null);
        } else {
            SmsSenderMethodHandler handler = new SmsSenderMethodHandler(registrar, result, address, body, sentId, subId);
            this.registrar.addRequestPermissionsResultListener(handler);
            handler.handle(this.permissions);
        }
    } else {
        result.notImplemented();
    }
}
 
Example 4
Source File: TencentImPlugin.java    From FlutterTencentImPlugin with Apache License 2.0 6 votes vote down vote up
/**
 * 腾讯云 未决审核
 *
 * @param methodCall 方法调用对象
 * @param result     返回结果对象
 */
private void examinePendency(MethodCall methodCall, final Result result) {
    // 类型
    int type = this.getParam(methodCall, result, "type");
    // 用户Id
    String id = this.getParam(methodCall, result, "id");
    // 好友备注
    String remark = methodCall.argument("remark");

    // 未决审核
    TIMFriendResponse response = new TIMFriendResponse();
    response.setIdentifier(id);
    response.setResponseType(type);
    response.setRemark(remark);
    TIMFriendshipManager.getInstance().doResponse(response, new ValueCallBack<TIMFriendResult>(result));
}
 
Example 5
Source File: FlutterFlipperkitPlugin.java    From flutter_flipperkit with MIT License 6 votes vote down vote up
private List<NetworkReporter.Header> convertHeader(MethodCall call) {
    Map<String, Object> argHeaders = call.argument("headers");
    List<NetworkReporter.Header> list = new ArrayList<>();

    if (argHeaders != null) {
        Set<String> keys = argHeaders.keySet();
        for (String key : keys) {
            Object value = argHeaders.get(key);

            String valueString;
            if (value instanceof ArrayList) {
                List values = (ArrayList) value;
                StringBuilder builder = new StringBuilder();
                for (Object obj : values) {
                    builder.append(obj);
                }
                valueString = builder.toString();
            } else {
                valueString = (String) value;
            }
            list.add(new NetworkReporter.Header(key, valueString));
        }
    }
    return list;
}
 
Example 6
Source File: LeancloudArgsConverter.java    From leancloud_flutter_plugin with MIT License 5 votes vote down vote up
static JSONObject getAVUserJsonObject(MethodCall call, MethodChannel.Result result) {
    String key = "avUser";
    Object arg = call.argument(key);
    if (arg == null) {
        result.error("missing-arg", "Arg '" + key + "' can't be null, set empty value. PLEASE FIX IT!", null);
        return null;
    } else {
        return JSON.parseObject(arg.toString());
    }
}
 
Example 7
Source File: LeancloudArgsConverter.java    From leancloud_flutter_plugin with MIT License 5 votes vote down vote up
static String getStringValue(MethodCall call, MethodChannel.Result result, String key) {
    Object arg = call.argument(key);
    if (arg == null) {
        result.error("missing-arg", "Arg '" + key + "' can't be null, set empty value. PLEASE FIX IT!", null);
        return "";
    } else {
        return arg.toString();
    }
}
 
Example 8
Source File: AudioQueryDelegate.java    From flutter_audio_query with MIT License 5 votes vote down vote up
/**
 * Method used to handle all method calls that is about playlist.
 * @param call Method call
 * @param result results input
 */
@Override
public void playlistSourceHandler(MethodCall call, MethodChannel.Result result){
    PlaylistLoader.PlayListMethodType type =
            PlaylistLoader.PlayListMethodType.values()[ (int) call.argument(PLAYLIST_METHOD_TYPE)];

    switch (type){
        case READ:
            if ( canIbeDependency(call, result)){

                if (m_permissionManager.isPermissionGranted(Manifest.permission.READ_EXTERNAL_STORAGE) ){
                    clearPendencies();
                    handleReadOnlyMethods(call, result);
                }
                else
                    m_permissionManager.askForPermission(Manifest.permission.READ_EXTERNAL_STORAGE,
                            REQUEST_CODE_PERMISSION_READ_EXTERNAL);
            } else finishWithAlreadyActiveError(result);
            break;

        case WRITE:
            if ( canIbeDependency(call, result)){

                if (m_permissionManager.isPermissionGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE) ){
                    clearPendencies();
                    handleWriteMethods(call, result);
                }
                else
                    m_permissionManager.askForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE,
                            REQUEST_CODE_PERMISSION_WRITE_EXTERNAL);
            } else finishWithAlreadyActiveError(result);
            break;

        default:
            result.notImplemented();
            break;
    }
}
 
Example 9
Source File: FlutterDownloaderPlugin.java    From flutter_downloader with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void remove(MethodCall call, MethodChannel.Result result) {
    String taskId = call.argument("task_id");
    boolean shouldDeleteContent = call.argument("should_delete_content");
    DownloadTask task = taskDao.loadTask(taskId);
    if (task != null) {
        if (task.status == DownloadStatus.ENQUEUED || task.status == DownloadStatus.RUNNING) {
            WorkManager.getInstance(context).cancelWorkById(UUID.fromString(taskId));
        }
        if (shouldDeleteContent) {
            String filename = task.filename;
            if (filename == null) {
                filename = task.url.substring(task.url.lastIndexOf("/") + 1, task.url.length());
            }

            String saveFilePath = task.savedDir + File.separator + filename;
            File tempFile = new File(saveFilePath);
            if (tempFile.exists()) {
                tempFile.delete();
            }
        }
        taskDao.deleteTask(taskId);

        NotificationManagerCompat.from(context).cancel(task.primaryId);

        result.success(null);
    } else {
        result.error("invalid_task_id", "not found task corresponding to given task id", null);
    }
}
 
Example 10
Source File: NativeDeviceOrientationPlugin.java    From flutter_native_device_orientation with MIT License 5 votes vote down vote up
@Override
public void onMethodCall(MethodCall call, final Result result) {
    switch (call.method) {
        case "getOrientation":
            Boolean useSensor = call.argument("useSensor");

            if(useSensor != null && useSensor){
                // we can't immediately retrieve a orientation from the sensor. We have to start listening
                // and return the first orientation retrieved.
                reader.getSensorOrientation(new IOrientationListener.OrientationCallback(){

                    @Override
                    public void receive(OrientationReader.Orientation orientation) {
                        result.success(orientation.name());
                    }
                });
            }else{
                result.success(reader.getOrientation().name());
            }
            break;

        case "pause":
            pause();
            result.success(null);
            break;

        case "resume":
            resume();
            result.success(null);
            break;
        default:
            result.notImplemented();
    }
}
 
Example 11
Source File: OpenFilePlugin.java    From open_file with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@SuppressLint("NewApi")
public void onMethodCall(MethodCall call, @NonNull Result result) {
    isResultSubmitted = false;
    if (call.method.equals("open_file")) {
        filePath = call.argument("file_path");
        this.result = result;

        if (call.hasArgument("type") && call.argument("type") != null) {
            typeString = call.argument("type");
        } else {
            typeString = getFileType(filePath);
        }
        if (pathRequiresPermission()) {
            if (hasPermission(Manifest.permission.READ_EXTERNAL_STORAGE)) {
                if (TYPE_STRING_APK.equals(typeString)) {
                    openApkFile();
                    return;
                }
                startActivity();
            } else {
                ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_CODE);
            }
        } else {
            startActivity();
        }
    } else {
        result.notImplemented();
        isResultSubmitted = true;
    }
}
 
Example 12
Source File: LeancloudArgsConverter.java    From leancloud_flutter_plugin with MIT License 5 votes vote down vote up
static String getStringValue(MethodCall call, MethodChannel.Result result, String key) {
    Object arg = call.argument(key);
    if (arg == null) {
        result.error("missing-arg", "Arg '" + key + "' can't be null, set empty value. PLEASE FIX IT!", null);
        return "";
    } else {
        return arg.toString();
    }
}
 
Example 13
Source File: AudioQueryDelegate.java    From flutter_audio_query with MIT License 4 votes vote down vote up
/**
 * This method handle all methods calls that need write something on
 * device memory.
 * @param call
 * @param result
 */
private void handleWriteMethods(MethodCall call, MethodChannel.Result result){
    String playlistId;
    String songId;
    final String keyPlaylistName = "playlist_name";
    final String keyPlaylistId = "playlist_id";
    final String keySongId = "song_id";

    final String keyFromPosition = "from";
    final String keyToPosition = "to";

    switch (call.method){

        case "createPlaylist":
            String name = call.argument(keyPlaylistName);
            m_playlistLoader.createPlaylist(result, name);
            break;

        case "addSongToPlaylist":
            playlistId = call.argument( keyPlaylistId );
            songId = call.argument( keySongId );
            m_playlistLoader.addSongToPlaylist(result, playlistId, songId);
            break;

        case "removeSongFromPlaylist":
            playlistId = call.argument(keyPlaylistId);
            songId = call.argument(keySongId);
            m_playlistLoader.removeSongFromPlaylist(result, playlistId, songId);
            break;

        case "removePlaylist":
            playlistId = call.argument(keyPlaylistId);
            m_playlistLoader.removePlaylist(result, playlistId);
            break;

        case "moveSong":
            playlistId = call.argument(keyPlaylistId);
            m_playlistLoader.moveSong(result, playlistId,
                    ((int) call.argument(keyFromPosition) ),
                    ((int)call.argument(keyToPosition))
            );
            break;

        default:
            result.notImplemented();
    }
}
 
Example 14
Source File: TencentImPlugin.java    From FlutterTencentImPlugin with Apache License 2.0 4 votes vote down vote up
/**
 * 腾讯云 创建群组
 *
 * @param methodCall 方法调用对象
 * @param result     返回结果对象
 */
private void createGroup(MethodCall methodCall, final Result result) {
    // 群类型
    String type = this.getParam(methodCall, result, "type");
    // 群名称
    String name = this.getParam(methodCall, result, "name");
    // 群ID
    String groupId = methodCall.argument("groupId");
    // 群公告
    String notification = methodCall.argument("notification");
    // 群简介
    String introduction = methodCall.argument("introduction");
    // 群头像
    String faceUrl = methodCall.argument("faceUrl");
    // 加群选项
    String addOption = methodCall.argument("addOption");
    // 最大群成员数
    Integer maxMemberNum = methodCall.argument("maxMemberNum");
    // 默认群成员
    List<TIMGroupMemberInfo> members = methodCall.argument("members") == null ? new ArrayList() : new ArrayList<TIMGroupMemberInfo>(JSON.parseArray(this.getParam(methodCall, result, "members").toString(), GroupMemberInfo.class));

    // 创建参数对象
    TIMGroupManager.CreateGroupParam param = new TIMGroupManager.CreateGroupParam(type, name);
    param.setGroupId(groupId);
    param.setNotification(notification);
    param.setIntroduction(introduction);
    param.setFaceUrl(faceUrl);
    param.setMembers(members);
    param.setAddOption(addOption != null ? TIMGroupAddOpt.valueOf(addOption) : null);
    if (maxMemberNum != null) {
        param.setMaxMemberNum(maxMemberNum);
    }

    // 创建群
    TIMGroupManager.getInstance().createGroup(param, new ValueCallBack<String>(result) {
        @Override
        public void onSuccess(String s) {
            result.success(s);
        }
    });
}
 
Example 15
Source File: FlutterDownloaderPlugin.java    From flutter_downloader with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void cancel(MethodCall call, MethodChannel.Result result) {
    String taskId = call.argument("task_id");
    WorkManager.getInstance(context).cancelWorkById(UUID.fromString(taskId));
    result.success(null);
}
 
Example 16
Source File: MediaPlayerPlugin.java    From media_player with MIT License 4 votes vote down vote up
private void onMethodCall(MethodCall call, Result result, long textureId, VideoPlayer player) {

      switch (call.method) {
    case "setSource":
      Map source = (HashMap) call.argument("source");
      Log.d(TAG, "Source=" + source.toString());
      player.setSource(source, result);
      // result.success(null);
      break;
    case "setPlaylist":
      List<Map> playlist = (List<Map>) call.argument("playlist");
      Log.d(TAG, "Playlist=" + playlist.toString());
      player.setPlaylist(playlist, result);
      // result.success(null);
      break;
    case "setLooping":
      player.setLooping((Boolean) call.argument("looping"));
      result.success(null);
      break;
    case "setVolume":
      player.setVolume((Double) call.argument("volume"));
      result.success(null);
      break;
    case "play":
      Log.i(TAG, "method call play");
      player.play();
      result.success(null);
      break;
    case "pause":
      player.pause();
      result.success(null);
      break;
    case "seekTo":
      int location = ((Number) call.argument("location")).intValue();
      int index = ((Number) call.argument("index")).intValue();
      player.seekTo(location, index);
      result.success(null);
      break;
    case "position":
      result.success(player.getPosition());
      break;
    case "dispose":
       Log.d(TAG, "calling dispose on player instance android");
      player.dispose();
      boolean background = call.argument("isBackground");
      if (background)
        audioServiceBinder.removePlayer(textureId);
      else
        videoPlayers.remove(textureId);
      result.success(null);
      break;
    case "retry":
      player.retry();
      result.success(null);
      break;  
    default:
      result.notImplemented();
      break;
    }
  }
 
Example 17
Source File: TencentImPlugin.java    From FlutterTencentImPlugin with Apache License 2.0 4 votes vote down vote up
/**
 * 腾讯云 下载视频
 *
 * @param methodCall 方法调用对象
 * @param result     返回结果对象
 */
private void downloadVideo(MethodCall methodCall, final Result result) {
    final String path = methodCall.argument("path");

    // 如果文件存在,则不进行下一步操作
    if (path != null && new File(path).exists()) {
        result.success(path);
        return;
    }

    // 获得消息后设置
    TencentImUtils.getTimMessage(methodCall, result, new ValueCallBack<TIMMessage>(result) {
        @Override
        public void onSuccess(TIMMessage message) {
            TIMElem elem = message.getElement(0);
            if (elem.getType() == TIMElemType.Video) {
                final TIMVideoElem videoElem = (TIMVideoElem) elem;
                // 如果没有填充目录,则获得临时目录
                String finalPath = path;
                if (finalPath == null || "".equals(finalPath)) {
                    finalPath = context.getExternalCacheDir().getPath() + File.separator + videoElem.getVideoInfo().getUuid();
                }

                // 如果文件存在则不进行下载
                if (new File(finalPath).exists()) {
                    result.success(finalPath);
                    return;
                }

                final String finalPath1 = finalPath;
                // 获得消息信息
                TencentImUtils.getMessageInfo(Collections.singletonList(message), new ValueCallBack<List<MessageEntity>>(result) {
                    @Override
                    public void onSuccess(final List<MessageEntity> messageEntities) {
                        // 下载视频
                        videoElem.getVideoInfo().getVideo(finalPath1, new ValueCallBack<ProgressInfo>(result) {
                            @Override
                            public void onSuccess(ProgressInfo progressInfo) {
                                Map<String, Object> params = new HashMap<>(3, 1);
                                params.put("message", messageEntities.get(0));
                                params.put("path", finalPath1);
                                params.put("currentSize", progressInfo.getCurrentSize());
                                params.put("totalSize", progressInfo.getTotalSize());
                                TencentImListener.invokeListener(ListenerTypeEnum.DownloadProgress, params);
                            }
                        }, new VoidCallBack(result) {
                            @Override
                            public void onSuccess() {
                                result.success(finalPath1);
                            }
                        });
                    }
                });
            }
        }
    });
}
 
Example 18
Source File: ESenseManagerMethodCallHandler.java    From flutter-plugins with MIT License 4 votes vote down vote up
@Override
public void onMethodCall(MethodCall call, Result rawResult) {
    Result result = new MainThreadResult(rawResult);
    boolean success;

    switch (call.method) {
        case "connect":
            final String name = call.argument("name");
            manager = new ESenseManager(name, registrar.activity().getApplicationContext(), eSenseConnectionEventStreamHandler);
            connected = manager.connect(TIMEOUT);
            result.success(connected);
            break;
        case "disconnect":
            connected = manager.disconnect();
            result.success(connected);
            break;
        case "isConnected":
            connected = manager.isConnected();
            result.success(connected);
            break;
        case "setSamplingRate":
            samplingRate = call.argument("rate");
            result.success(true);
            break;
        case "getDeviceName":
            success = manager.getDeviceName();
            result.success(success);
            break;
        case "setDeviceName":
            String deviceName = call.argument("deviceName");
            success = manager.setDeviceName(deviceName);
            result.success(success);
            break;
        case "getBatteryVoltage":
            success = manager.getBatteryVoltage();
            result.success(success);
            break;
        case "getAccelerometerOffset":
            success = manager.getAccelerometerOffset();
            result.success(success);
            break;
        case "getAdvertisementAndConnectionInterval":
            success = manager.getAdvertisementAndConnectionInterval();
            result.success(success);
            break;
        case "setAdvertisementAndConnectiontInterval":
            final int advMinInterval = call.argument("advMinInterval");
            final int advMaxInterval = call.argument("advMaxInterval");
            final int connMinInterval = call.argument("connMinInterval");
            final int connMaxInterval = call.argument("connMaxInterval");
            success = manager.setAdvertisementAndConnectiontInterval(
                    advMinInterval,
                    advMaxInterval,
                    connMinInterval,
                    connMaxInterval);
            result.success(success);
            break;
        case "getSensorConfig":
            success = manager.getSensorConfig();
            result.success(success);
            break;
        case "setSensorConfig":
            // TODO - implement serialization of ESenseConfig object btw. Java and Dart.
            // ESenseConfig config = call.argument("config");
            // success = manager.setSensorConfig(config);
            // result.success(success);
            result.notImplemented();
            break;
        default:
            result.notImplemented();
    }
}
 
Example 19
Source File: FlutterCrashlyticsPlugin.java    From flutter_crashlytics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
void onInitialisedMethodCall(MethodCall call, MethodChannel.Result result) {
    final CrashlyticsCore core = Crashlytics.getInstance().core;
    switch (call.method) {
        case "log":
            if (call.arguments instanceof String) {
                core.log(call.arguments.toString());
            } else {
                try {
                    final List<Object> info = (List<Object>) call.arguments;
                    core.log(parseStringOrEmpty(info.get(0)) + ": " + info.get(1) + " " + info.get(2));
                } catch (ClassCastException ex) {
                    Log.d("FlutterCrashlytics", "" + ex.getMessage());
                }
            }
            result.success(null);
            break;
        case "setInfo":
            final Object currentInfo = call.argument("value");
            if (currentInfo instanceof String) {
                core.setString((String) call.argument("key"), (String) call.argument("value"));
            } else if (currentInfo instanceof Integer) {
                core.setInt((String) call.argument("key"), (Integer) call.argument("value"));
            } else if (currentInfo instanceof Double) {
                core.setDouble((String) call.argument("key"), (Double) call.argument("value"));
            } else if (currentInfo instanceof Boolean) {
                core.setBool((String) call.argument("key"), (Boolean) call.argument("value"));
            } else if (currentInfo instanceof Float) {
                core.setFloat((String) call.argument("key"), (Float) call.argument("value"));
            } else if (currentInfo instanceof Long) {
                core.setLong((String) call.argument("key"), (Long) call.argument("value"));
            } else {
                core.log("ignoring unknown type with key " + call.argument("key") + "and value "
                        + call.argument("value"));
            }
            result.success(null);
            break;
        case "setUserInfo":
            core.setUserEmail((String) call.argument("email"));
            core.setUserName((String) call.argument("name"));
            core.setUserIdentifier((String) call.argument("id"));
            result.success(null);
            break;
        case "reportCrash":
            final Map<String, Object> exception = (Map<String, Object>) call.arguments;
            final boolean forceCrash = tryParseForceCrash(exception.get("forceCrash"));
            final FlutterException throwable = Utils.create(exception);
            if (forceCrash) {
                //Start a new activity to not crash directly under onMethod call, or it will crash JNI instead of a clean exception
                final Intent intent = new Intent(context, CrashActivity.class);
                intent.putExtra("exception", throwable);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                context.startActivity(intent);
            } else {
                Log.d("Crashlytics", "this thing is reporting");
                core.logException(throwable);
            }

            result.success(null);
            break;
        default:
            result.notImplemented();
            break;
    }
}
 
Example 20
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 3 votes vote down vote up
private void setWiFiAPSSID(MethodCall poCall, Result poResult) {
    String sAPSSID = poCall.argument("ssid");

    WifiConfiguration oWiFiConfig = moWiFiAPManager.getWifiApConfiguration();

    oWiFiConfig.SSID = sAPSSID;

    moWiFiAPManager.setWifiApConfiguration(oWiFiConfig);

    poResult.success(null);
}