如何使用 Mobile(T53/T58) 在本机反应中集成 Zebra 扫描仪(2D 方式成像器)

问题描述 投票:0回答:1

我正在使用 React Native 应用程序版本 - 0.71.11。我有一个现有的应用程序,具有用于条形码扫描的相机功能,但我们想将斑马扫描仪(2D 方式成像器)集成到此应用程序中。因此,我可以使用 Zebra 手机(t53/t58)使用其内部扫描仪扫描任何条形码。

任何人都可以分享任何想法吗?

react-native barcode-scanner scanning zebra-scanners zebra
1个回答
0
投票

有文章和演示应用程序https://github.com/darryncampbell/DataWedgeReactNative,虽然有点过时,但应该仍然可以工作。

基于这些文章,我使用react-hooks实现了自己的解决方案,它运行完美(react-native 0.73.6,expo 50.0.17,本地开发版本)

唯一的依赖是

"react-native-datawedge-intents"
库。

我创建了文件 zebraScanner.js:

import { useEffect } from "react";
import { NativeEventEmitter } from "react-native";
import DataWedgeIntents from "react-native-datawedge-intents";

export function useZebraScanner(callback) {
  return useEffect(() => {
    const dataWedgeEmmiter = new NativeEventEmitter();
    const dataWedgeSubscription = dataWedgeEmmiter.addListener(
      "datawedge_broadcast_intent",
      (intent) => handleDataWedgeIntentReceived(intent, callback)
    );

    //registerBroadcastReceiver();

    return () => {
      dataWedgeSubscription.remove();
    };
  }, [callback]);
}

function handleDataWedgeIntentReceived(intent, callback) {
  //console.log("Intent received: " + JSON.stringify(intent));

  if (
    Object.hasOwn(intent, "com.symbol.datawedge.api.RESULT_GET_VERSION_INFO")
  ) {
    //just for debug, in future i can send
    // sendDataWedgeCommand("com.symbol.datawedge.api.GET_VERSION_INFO", "");
    // and receive DataWedge version to tweak it's configuration

    var versionInfo =
      intent["com.symbol.datawedge.api.RESULT_GET_VERSION_INFO"];
    console.log("Version Info: " + JSON.stringify(versionInfo));
    var datawedgeVersion = versionInfo["DATAWEDGE"];
    console.log("Datawedge version: " + datawedgeVersion);
  } else if (!Object.hasOwn(intent, "RESULT_INFO")) {
    //!barcode received!
    callback(intent["com.symbol.datawedge.data_string"]);
  } else if (Object.hasOwn(intent, "RESULT_INFO")) {
    //just for debug
    var commandResult =
      intent.RESULT +
      " (" +
      intent.COMMAND.substring(
        intent.COMMAND.lastIndexOf(".") + 1,
        intent.COMMAND.length
      ) +
      ")" +
      JSON.stringify(intent.RESULT_INFO);
    console.log(
      "DATAWEDGE COMMAND RECEIVED (result of SET config ETC)",
      commandResult
    );
  }
}

export function useConfigureZebraScanner() {
  return useEffect(() => {
    registerBroadcastReceiver();
    createOrUpdateDataWedgeProfile();
  }, []);
}

function registerBroadcastReceiver() {
  DataWedgeIntents.registerBroadcastReceiver({
    filterActions: [
      "com.CCW.DoryDriver.ACTION",
      "com.symbol.datawedge.api.RESULT_ACTION",
    ],
    filterCategories: ["android.intent.category.DEFAULT"],
  });
}

function sendDataWedgeCommand(extraName, extraValue) {
  console.log(
    "Sending Command: " + extraName + ", " + JSON.stringify(extraValue)
  );
  var broadcastExtras = {};
  broadcastExtras[extraName] = extraValue;
  broadcastExtras["SEND_RESULT"] = "true"; //toto neviem co je
  DataWedgeIntents.sendBroadcastWithExtras({
    action: "com.symbol.datawedge.api.ACTION",
    extras: broadcastExtras,
  });
}

function createOrUpdateDataWedgeProfile() {
  //  Set the new configuration
  const profileConfig = {
    PROFILE_NAME: "DoryDriver",
    PROFILE_ENABLED: "true",
    CONFIG_MODE: "CREATE_IF_NOT_EXIST",
    PLUGIN_CONFIG: {
      PLUGIN_NAME: "BARCODE",
      RESET_CONFIG: "true",
      PARAM_LIST: {
        //"current-device-id": this.selectedScannerId,
        scanner_selection: "auto",
        scanner_input_enabled: "true", //??
        //"decoder_ean8": "" + this.state.ean8checked,
        //"decoder_ean13": "" + this.state.ean13checked,
        //decoder_code128: "true",
        //"decoder_code39": "" + this.state.code39checked
      },
    },
    APP_LIST: [{ PACKAGE_NAME: "com.CCW.DoryDriver", ACTIVITY_LIST: ["*"] }],
  };
  sendDataWedgeCommand("com.symbol.datawedge.api.SET_CONFIG", profileConfig);

  const profileIntentPluginConfig = {
    PROFILE_NAME: "DoryDriver",
    CONFIG_MODE: "UPDATE",
    PLUGIN_CONFIG: {
      PLUGIN_NAME: "INTENT",
      RESET_CONFIG: "true",
      PARAM_LIST: {
        intent_output_enabled: "true",
        intent_action: "com.CCW.DoryDriver.ACTION",
        intent_delivery: "2", //! 2: Broadcast
        intent_category: "android.intent.category.DEFAULT",
      },
    },
  };

  sendDataWedgeCommand(
    "com.symbol.datawedge.api.SET_CONFIG",
    profileIntentPluginConfig
  );
}

然后我就打电话

  useConfigureZebraScanner();

在应用程序的根屏幕上创建所需的 Zebra Data Wedge 配置文件(如果不存在)..

并致电

useZebraScanner((code) => {
    alert(code);
  });

在屏幕上我想使用扫描仪,我通过回调来处理收到的代码

© www.soinside.com 2019 - 2024. All rights reserved.