Java Code Examples for io.flutter.plugin.common.MethodChannel.Result#error()

The following examples show how to use io.flutter.plugin.common.MethodChannel.Result#error() . 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: TflitePlugin.java    From flutter_tflite with MIT License 6 votes vote down vote up
RunPix2PixOnFrame(HashMap args, Result result) throws IOException {
  super(args, result);
  List<byte[]> bytesList = (ArrayList) args.get("bytesList");
  double mean = (double) (args.get("imageMean"));
  IMAGE_MEAN = (float) mean;
  double std = (double) (args.get("imageStd"));
  IMAGE_STD = (float) std;
  int imageHeight = (int) (args.get("imageHeight"));
  int imageWidth = (int) (args.get("imageWidth"));
  int rotation = (int) (args.get("rotation"));

  outputType = args.get("outputType").toString();
  startTime = SystemClock.uptimeMillis();
  input = feedInputTensorFrame(bytesList, imageHeight, imageWidth, IMAGE_MEAN, IMAGE_STD, rotation);
  output = ByteBuffer.allocateDirect(input.limit());
  output.order(ByteOrder.nativeOrder());

  if (input.limit() == 0) {
    result.error("Unexpected input position, bad file?", null, null);
    return;
  }
  if (output.position() != 0) {
    result.error("Unexpected output position", null, null);
    return;
  }
}
 
Example 2
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 6 votes vote down vote up
private void loadWifiList(final Result poResult) {
    try {

        int PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION = 65655434;
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && moContext.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED){
            moActivity.requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION);
        }

        moWiFi.startScan();

        poResult.success(handleNetworkScanResult().toString());

    } catch (Exception e) {
        poResult.error("Exception", e.getMessage(), null);
    }
}
 
Example 3
Source File: TflitePlugin.java    From flutter_tflite with MIT License 6 votes vote down vote up
RunPix2PixOnImage(HashMap args, Result result) throws IOException {
  super(args, result);
  path = args.get("path").toString();
  double mean = (double) (args.get("imageMean"));
  IMAGE_MEAN = (float) mean;
  double std = (double) (args.get("imageStd"));
  IMAGE_STD = (float) std;

  outputType = args.get("outputType").toString();
  startTime = SystemClock.uptimeMillis();
  input = feedInputTensorImage(path, IMAGE_MEAN, IMAGE_STD);
  output = ByteBuffer.allocateDirect(input.limit());
  output.order(ByteOrder.nativeOrder());
  if (input.limit() == 0) {
    result.error("Unexpected input position, bad file?", null, null);
    return;
  }
  if (output.position() != 0) {
    result.error("Unexpected output position", null, null);
    return;
  }
}
 
Example 4
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 6 votes vote down vote up
private void removeWifiNetwork(MethodCall poCall, Result poResult) {
    String prefix_ssid = poCall.argument("ssid");
    if (prefix_ssid.equals("")) {
        poResult.error("Error", "No prefix SSID was given!", null);
    }

    List<WifiConfiguration> mWifiConfigList = moWiFi.getConfiguredNetworks();
    for (WifiConfiguration wifiConfig : mWifiConfigList) {
        String comparableSSID = ('"' + prefix_ssid); //Add quotes because wifiConfig.SSID has them
        if (wifiConfig.SSID.startsWith(comparableSSID)) {
            moWiFi.removeNetwork(wifiConfig.networkId);
            moWiFi.saveConfiguration();
            poResult.success(true);
            return;
        }
    }
    poResult.success(false);
}
 
Example 5
Source File: TflitePlugin.java    From flutter_tflite with MIT License 6 votes vote down vote up
RunPix2PixOnBinary(HashMap args, Result result) throws IOException {
  super(args, result);
  byte[] binary = (byte[]) args.get("binary");
  outputType = args.get("outputType").toString();
  startTime = SystemClock.uptimeMillis();
  input = ByteBuffer.wrap(binary);
  output = ByteBuffer.allocateDirect(input.limit());
  output.order(ByteOrder.nativeOrder());

  if (input.limit() == 0) {
    result.error("Unexpected input position, bad file?", null, null);
    return;
  }
  if (output.position() != 0) {
    result.error("Unexpected output position", null, null);
    return;
  }
}
 
Example 6
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 5 votes vote down vote up
private void getBSSID(Result poResult) {
    WifiInfo info = moWiFi.getConnectionInfo();

    String bssid = info.getBSSID();

    try {
        poResult.success(bssid.toUpperCase());
    } catch (Exception e) {
        poResult.error("Exception", e.getMessage(), null);
    }
}
 
Example 7
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 5 votes vote down vote up
/**
 * This is a network that does not broadcast its SSID, so an
 * SSID-specific probe request must be used for scans.
 */
private void isSSIDHidden(Result poResult) {
    WifiConfiguration oWiFiConfig = moWiFiAPManager.getWifiApConfiguration();
    if (oWiFiConfig != null && oWiFiConfig.hiddenSSID) {
        poResult.success(oWiFiConfig.hiddenSSID);
        return;
    }
    poResult.error("Exception", "Wifi AP not Supported", null);
}
 
Example 8
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 5 votes vote down vote up
/**
 * The network's SSID. Can either be an ASCII string,
 * which must be enclosed in double quotation marks
 * (e.g., {@code "MyNetwork"}), or a string of
 * hex digits, which are not enclosed in quotes
 * (e.g., {@code 01a243f405}).
 */
private void getWiFiAPSSID(Result poResult) {
    WifiConfiguration oWiFiConfig = moWiFiAPManager.getWifiApConfiguration();
    if (oWiFiConfig != null && oWiFiConfig.SSID != null) {
        poResult.success(oWiFiConfig.SSID);
        return;
    }
    poResult.error("Exception", "SSID not found", null);
}
 
Example 9
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 5 votes vote down vote up
/**
 *
 * @param poCall
 * @param poResult
 */
private void setMACFiltering(MethodCall poCall, Result poResult) {
    boolean bEnable = poCall.argument("state");

    // Log.e(this.getClass().toString(), "TODO : Develop function to enable/disable MAC filtering...");

    poResult.error("TODO", "Develop function to enable/disable MAC filtering...", null);
}
 
Example 10
Source File: WifiPlugin.java    From wifi with MIT License 5 votes vote down vote up
@Override
public void onMethodCall(MethodCall call, Result result) {
    if (registrar.activity() == null) {
        result.error("no_activity", "wifi plugin requires a foreground activity.", null);
        return;
    }
    switch (call.method) {
        case "ssid":
            delegate.getSSID(call, result);
            break;
        case "level":
            delegate.getLevel(call, result);
            break;
        case "ip":
            delegate.getIP(call, result);
            break;
        case "list":
            delegate.getWifiList(call, result);
            break;
        case "connection":
            delegate.connection(call, result);
            break;
        default:
            result.notImplemented();
            break;
    }
}
 
Example 11
Source File: FlutterIncallManagerPlugin.java    From flutter-incall-manager with ISC License 5 votes vote down vote up
public void checkCameraPermission(Result result) {
    Log.d(TAG, "FlutterInCallManager.checkCameraPermission(): enter");
    _checkCameraPermission();
    if (cameraPermission.equals("unknow")) {
        Log.d(TAG, "FlutterInCallManager.checkCameraPermission(): failed");
        result.error("checkCameraPermission", "checkCameraPermission failed", null);
    } else {
        result.success(cameraPermission);
    }
}
 
Example 12
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private void deleteMessageById(MethodCall call, Result result) {
  HashMap<String, Object> map = call.arguments();
  Conversation conversation;
  String messageId;

  try {
    JSONObject params = new JSONObject(map);

    conversation = JMessageUtils.getConversation(params);

    if (conversation == null) {
      handleResult(ERR_CODE_CONVERSATION, "Can't get conversation", result);
      return;
    }

    messageId = params.getString("messageId");
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }

  boolean success = conversation.deleteMessage(Integer.parseInt(messageId));

  if (success) {
    result.success(null);
  } else {
    HashMap error = new HashMap();
    error.put("code", ERR_CODE_MESSAGE);
    error.put("description", ERR_MSG_MESSAGE);
    result.error(ERR_CODE_MESSAGE + "", ERR_MSG_MESSAGE, "");
  }
}
 
Example 13
Source File: ContactsServicePlugin.java    From flutter_contacts with MIT License 5 votes vote down vote up
@Override
public void onMethodCall(MethodCall call, Result result) {
  switch(call.method){
    case "getContacts":
      this.getContacts((String)call.argument("query"), (boolean)call.argument("withThumbnails"), (boolean)call.argument("photoHighResolution"), result);
      break;
    case "getContactsForPhone":
      this.getContactsForPhone((String)call.argument("phone"), (boolean)call.argument("withThumbnails"), (boolean)call.argument("photoHighResolution"), result);
      break;
    case "addContact":
      Contact c = Contact.fromMap((HashMap)call.arguments);
      if(this.addContact(c)) {
        result.success(null);
      } else{
        result.error(null, "Failed to add the contact", null);
      }
      break;
    case "deleteContact":
      Contact ct = Contact.fromMap((HashMap)call.arguments);
      if(this.deleteContact(ct)){
        result.success(null);
      } else{
        result.error(null, "Failed to delete the contact, make sure it has a valid identifier", null);
      }
      break;
    case "updateContact":
      Contact ct1 = Contact.fromMap((HashMap)call.arguments);
      if(this.updateContact(ct1)) {
        result.success(null);
      } else {
        result.error(null, "Failed to update the contact, make sure it has a valid identifier", null);
      }
      break;
    default:
      result.notImplemented();
      break;
  }
}
 
Example 14
Source File: FlutterMobileVisionPlugin.java    From flutter_mobile_vision with MIT License 5 votes vote down vote up
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result rawResult) {
    if (activity == null) {
        rawResult.error("no_activity",
                "Flutter Mobile Vision plugin requires a foreground activity.",
                null);
        return;
    }

    MethodChannel.Result result = new MethodResultWrapper(rawResult);

    switch (call.method) {
        case "start":
            delegate.start(call, result);
            break;

        case "scan":
            delegate.scan(call, result);
            break;

        case "read":
            delegate.read(call, result);
            break;

        case "face":
            delegate.face(call, result);
            break;

        default:
            result.notImplemented();
    }
}
 
Example 15
Source File: AuthorizeModule.java    From reader-sdk-flutter-plugin with Apache License 2.0 5 votes vote down vote up
public void authorizedLocation(Result flutterResult) {
  if (ReaderSdk.authorizationManager().getAuthorizationState().isAuthorized()) {
    flutterResult.success(locationConverter.toMapObject(ReaderSdk.authorizationManager().getAuthorizationState().getAuthorizedLocation()));
  } else {
    flutterResult.error(
        ErrorHandlerUtils.USAGE_ERROR,
        ErrorHandlerUtils.getNativeModuleErrorMessage(FL_AUTH_LOCATION_NOT_AUTHORIZED),
        ErrorHandlerUtils.getDebugErrorObject(FL_AUTH_LOCATION_NOT_AUTHORIZED, FL_MESSAGE_AUTH_LOCATION_NOT_AUTHORIZED));
  }
}
 
Example 16
Source File: FlutterAudioQueryPlugin.java    From flutter_audio_query with MIT License 5 votes vote down vote up
@Override
public void onMethodCall(MethodCall call, Result result) {

    String source = call.argument("source");
    if (source != null ){

        switch (source){
            case "artist":
                m_delegate.artistSourceHandler(call, result);
                break;

            case "album":
                m_delegate.albumSourceHandler(call, result);
                break;

            case "song":
                m_delegate.songSourceHandler(call, result);
                break;

            case "genre":
                m_delegate.genreSourceHandler(call, result);
                break;

            case "playlist":
                m_delegate.playlistSourceHandler(call, result);
                break;

            default:
                result.error("unknown_source",
                            "method call was made by an unknown source", null);
                break;

        }
    }

    else {
        result.error("no_source", "There is no source in your method call", null);
    }
}
 
Example 17
Source File: FlutterQrReaderPlugin.java    From flutter_qr_reader with MIT License 5 votes vote down vote up
@SuppressLint("StaticFieldLeak")
void imgQrCode(MethodCall call, final Result result) {
  final String filePath = call.argument("file");
  if (filePath == null) {
    result.error("Not found data", null, null);
    return;
  }
  File file = new File(filePath);
  if (!file.exists()) {
    result.error("File not found", null, null);
  }

  new AsyncTask<String, Integer, String>() {
    @Override
    protected String doInBackground(String... params) {
      // 解析二维码/条码
      return QRCodeDecoder.syncDecodeQRCode(filePath);
    }
    @Override
    protected void onPostExecute(String s) {
      super.onPostExecute(s);
      if(null == s){
        result.error("not data", null, null);
      }else {
        result.success(s);
      }
    }
  }.execute(filePath);
}
 
Example 18
Source File: AndroidJobSchedulerPlugin.java    From android_job_scheduler with Apache License 2.0 5 votes vote down vote up
@Override
public void onMethodCall(MethodCall call, Result result) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        result.error("JobScheduler API is not available in API Level 20 and below.", "", null);
        return;
    }
    if (call.method.equals("scheduleEvery")) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            PersistableBundle bundle = AndroidJobSchedulerUtils.serializedDataToPersistableBundle((ArrayList<?>) call.arguments, mContext);

            AndroidJobScheduler.scheduleEvery(this.mContext, AndroidJobSchedulerUtils.persistableBundleToJobInfo(bundle));
            result.success(true);
        } else {
            result.success(false);
        }
    } else if (call.method.equals("cancelJob")) {
        final ArrayList<?> args = (ArrayList<?>) call.arguments;
        AndroidJobScheduler.cancelJob(this.mContext, (Integer) args.get(0));
    } else if (call.method.equals("cancelAllJobs")) {
        AndroidJobScheduler.cancelAllJobs(this.mContext);
    } else if (call.method.equals("getAllPendingJobs")) {
        List<JobInfo> jobs = AndroidJobScheduler.getAllPendingJobs(this.mContext);
        List<Integer> jobIds = new ArrayList<>();
        for(JobInfo job : jobs) {
            jobIds.add(job.getId());
        }
        result.success(jobIds);
    } else {
        result.notImplemented();
    }
}
 
Example 19
Source File: FlutterFlipperkitPlugin.java    From flutter_flipperkit with MIT License 5 votes vote down vote up
private void clientAddPlugin(MethodCall call, Result result) {
    if (call.hasArgument("id")) {
        final String pluginId = call.argument("id");
        if (pluginId == null) {
            result.error("", "", "");
            return;
        }
        // 当插件已经添加时,避免再次添加
        if (flipperClient.getPlugin(pluginId) != null) {
            result.success(true);
            return;
        }
        switch (pluginId) {
            case NetworkFlipperPlugin.ID:
                flipperClient.addPlugin(networkFlipperPlugin);
                break;
            case "Preferences":
                flipperClient.addPlugin(sharedPreferencesFlipperPlugin);
                break;
            case FlipperDatabaseBrowserPlugin.ID:
                flipperClient.addPlugin(flipperDatabaseBrowserPlugin);
                break;
            case FlipperReduxInspectorPlugin.ID:
                flipperClient.addPlugin(flipperReduxInspectorPlugin);
                break;
        }
    }

    result.success(true);
}
 
Example 20
Source File: MediaPlayerPlugin.java    From media_player with MIT License 4 votes vote down vote up
@Override
public void onMethodCall(MethodCall call, Result result) {

  // Log.i(TAG, "method call = " + call.method);
  switch (call.method) {

  case "create": {
    // if service is not created and app demands background player then we
    // have to call createVideoPlayer from onServiceConnected callback;
    // so let's save call and result and createVideoplayer will
    this.call = call;
    this.result = result;
    if (call.argument("isBackground")) {
      Log.i(TAG, "neeeded background exoplayer");

      if (audioServiceBinder == null) {
        Log.i(TAG, "calling BindeService");
        bindService();
      } else {
        createVideoPlayer();
      }
    } else {

      createVideoPlayer();
    }

    break;
  }
  default: {
    long textureId = ((Number) call.argument("textureId")).longValue();
    boolean background = call.argument("isBackground");
    VideoPlayer player = null;
    // Log.i(TAG, "TextureID: " + textureId + " background:" + background);
    if (background) {
      if (audioServiceBinder != null)
        player = audioServiceBinder.getPlayer(textureId);
    } else {
      // Log.i(TAG, "calling frontend player");
      player = videoPlayers.get(textureId);
    }

    if (!call.method.equals("position")) {
      // Log.i(TAG, "method called " + call.method);
    }
    if (player == null) {
      result.error("Unknown textureId", "No video player associated with texture id " + textureId, null);
      return;
    }
    onMethodCall(call, result, textureId, player);
    break;
  }
  }

}