@datalogic/cordova-plugin-datalogic

中文文档
0.4.1发布于 2019/08/27Apache-2.0零依赖近 30 天下载 3350

Datalogic Cordova SDK for Android devices

原始使用文档
文档目录9 节
  1. Installation
  2. Sample apps
  3. API Reference
  4. Namespaces
  5. barcodeManager
  6. autoScanTrigger
  7. keyboardManager
  8. ledManager
  9. scannerProperties

Datalogic Cordova Plugin

Library that exposes the Datalogic Android (Java) SDK as a Cordova plugin. It lets you receive barcode data from the scanner, as well as configure various scanner and device settings. It is available as a npm package for easy consumption here: @datalogic/cordova-plugin-datalogic.

Installation

You can install the plugin from the npm registry as follows:

npm i @datalogic/cordova-plugin-datalogic

...or use the following Cordova CLI command:

cordova plugin add @datalogic/cordova-plugin-datalogic

or, if you are using ionic, this ionic command:

ionic cordova plugin add @datalogic/cordova-plugin-datalogic

or, if you are using PhoneGap CLI, this phonegap command:

phonegap plugin add @datalogic/cordova-plugin-datalogic

## Publish new version

Install and use the [np tool](https://github.com/sindresorhus/np):

``` bash
npm install --global np
np

Sample apps

Several Ionic sample applications are provided to demonstrate using the plugin. You can find them here.

API Reference

All functions are asynchronous. All functions will, at a minimum, include successCallback and errorCallback parameters, both of which are callback functions.

  • successCallback will be called in normal cases, and will return an appropriate JSON object.

  • errorCallback will be called when there was an error, and will return a single error string.

Namespaces

NamespaceDescription
barcodeManagerreceive barcode data
autoScanTriggerwork the the autoscan features
keyboardManagerset usable device triggers
ledManagercontrol device LEDs
scannerPropertiesdefine availabled symbologies

barcodeManager


FunctionDescription
addReadListenerRegister to recieve barcode data on each scan.
pressTriggerSimulate a trigger button press.
releaseTriggerSimulate a trigger button release.

.addReadListener(successCallback, errorCallback): Object

Register to recieve barcode data on each scan. successCallback will be called every time a barcode is successfully scanned. Therefore, you will typically only need to call barcodeManager.addReadListener() once in your application.

Response
{
   "barcodeData": "EUG2997",
   "barcodeType": "CODE128"
}
Example
declare let barcodeManager : any;
...
barcodeManager.addReadListner(
   (data) => {
     parsedData = JSON.parse(data);
     alert(parsedData.barcodeData + ", " + parsedData.barcodeType);
   },
   (err)=>{ alert(err); }
);

.pressTrigger(successCallback, errorCallback): Object

Call this method to simulate a trigger button press. The method does not always immediately start a capture; instead it behaves like pressing a physical scan button.

Response

string with success message

Example
barcodeManager.pressTrigger(
  (data) => { alert(data); },
  (err) => { alert(err);}
);

.releaseTrigger(successCallback, errorCallback): Object

Call this method to simulate a release of a trigger button. The method does not always immediately stop a capture; instead it behaves like releasing a physical scan button.

Response

string with success message

Example
barcodeManager.releaseTrigger(
  (data) => { alert(data); },
  (err) => { alert(err);}
);

autoScanTrigger


FunctionDescription
isAvailableDetermine if the auto scan feature is available on this device.
getSupportedRangesGet the supported ranges of the autoscan feature.
getCurrentRangeGet the current range of the autoscan feature.
setCurrentRangeSet the current range of the autoscan feature.

.isAvailable(successCallback, errorCallback): Object

Determine if the auto scan feature is available on this device.

Response
  • available : boolean - indicates if autoscan is supported or not on this device.
{ "available": true }
Example
declare let autoScanTrigger : any;
isAvailable : boolean = false;
...
autoScanTrigger.isAvailable(
  (data) => {
    this.isAvailable = JSON.parse(data).available;
    alert(this.isAvailable);
  },
  (err) => { alert(err); }
);

.getSupportedRanges(successCallback, errorCallback): Object

Get the supported ranges of the autoscan feature.

Response

supportedRanges : array - provides array of ranges device supports. The array will be empty if device deos not support autoscan. Each object in the array contains:

  • id : integer - unique value for a step in the supported ranges
  • name : string - descriptive text related to the id

If AutoScan is not supported by device:

{ "supportedRanges":[] }

If AutoScan is supported:

{
  "supportedRanges":[
  {
    "id":0,
    "name":"Near"
  },
  {
    "id":1,
    "name":"Intermediate"
  },
  {
    "id":2,
    "name":"Far"
  }
  ]
}
Example
declare let autoScanTrigger : any;
autoScanTrigger.getSupportedRanges(
  (data) => {
    alert(JSON.parse(data).supportedRanges);
    if(this.supportedRanges.length == 0)
      alert("Device does not support Auto Scan");
  },
  (err) => { alert(err); }
);

.getCurrentRange(successCallback, errorCallback): Object

Get the current range of the autoscan feature.

Response

currentRange : object - contains 2 fields:

  • id : integer
  • name : string

If AutoScan is not supported by device:

{ "currentRange":null }

If AutoScan is supported:

{
  "currentRange":
  {
      "id":1,
      "name":"Intermediate"
  }
}
Example
declare let autoScanTrigger : any;
autoScanTrigger.getCurrentRange(
  (data) => {
    alert(JSON.parse(data).currentRange);
  },
  (err) => { alert(err); }
);

.setCurrentRange(id, successCallback, errorCallback): Object

Set the current range of the autoscan feature.

id : integer - should match one of the id values retrevied by the getSupportedRanges function.

Response

string with success message

Example

Set current range to "Intermediate"

autoScanTrigger.setCurrentRange(
  0,
  (data) => { alert(data); },
  (err) => { alert(err); }
);

keyboardManager


FunctionDescription
getAllAvailableTriggersGet all the available triggers of the device.
setAllAvailableTriggersSet all the devices triggers on or off.
setTriggersSet one or more triggers on or off.

.getAllAvailableTriggers (successCallback, errorCallback): Object

Get all the available triggers of the device.

Response

triggers : array - each object in the array contains:

  • enabled : boolean
  • id : integer
  • name : string

Typical resopsnse:

{
    "triggers":[
    {
        "enabled":true,
        "id":3,
        "name":"Front Trigger"
    },
    {
        "enabled":false,
        "id":4,
        "name":"Auto Scan Trigger"
    },
    {
        "enabled":false,
        "id":5,
        "name":"Motion Trigger"
    }
    ]
}
Example
keyboardManager.getAllAvailableTriggers(
  (data) => { alert(JSON.parse(data).triggers); },
  (err) => { alert(err); }
);

.setAllAvailableTriggers(enable, successCallback, errorCallback): Object

Set all the devices triggers on or off.

Response

string with success message

Example

Turn all triggers on.

keyboardManager.setAllAvailableTriggers(
  true,
  (data) => { alert(data); },
  (err) => { alert(err); }
);

.setTriggers(config, successCallback, errorCallback): Object

Set one or more triggers on or off. You will likely call getAllAvailableTriggers, edit the enabled flags of each returned object as desired, and then resubmit by calling setTriggers.

config : array - each ojbect in the array represents an individual trigger. Each object in the array contains:

  • id : integer
  • enabled : boolean
Response

string with success message

Example
//an array os supported triggers
triggers:{id: number, name: string, enabled: boolean}[]  = [];
...
keyboardManager.getAllAvailableTriggers(
  (data) => {
    this.triggers = JSON.parse(data).triggers;
    this.triggers[0].enabled = false;

    keyboardManager.setTriggers(
      this.triggers,
      (data) => { alert(data); },
      (err) => { alert(err);}
    );
  },
  (err) => { alert(err); }
);

ledManager


FunctionDescription
setLedSet various device LEDs.

.setLed(ledConfig, successCallback, errorCallback): Object

Set the various device LEDs. A list of enum values for LEDs can be found here.

Response

string with success message

Example
ledManager.setLed({"led": "LED_GOOD_READ", "enable": false}, null, null);

scannerProperties


FunctionDescription
editGet a list of supported properties along with the state of each (enabled or disabled).
storeApply changes to one or more properties with the values supplied.

.edit(successCallback, errorCallback): Object

Get a list of supported scanner properties along with the state of each (enabled or disabled).

Response

A single JSON object containing an object for each of the available symbologies. Each symbology contains, at a minimum, these fields:

  • enable : boolean - if scannner is set to detect this barcode type or not
  • supported : boolean - if the scanner supports the given barcode type or not
{
  "keyboardWedge":{"enable":true,"supported":true},
  "aztec":{"enable":true,"supported":true},
  "codabar":{"enable":true,"supported":true},
  "code128":{"enable":true,"supported":true},
  "code39":{"enable":true,"supported":true},
  "code93":{"enable":false,"supported":true},
  "composite":{"enable":false,"supported":true},
  "datamatrix":{"enable":true,"supported":true},
  "digimarc":{"enable":false,"supported":false},
  "discrete25":{"enable":false,"supported":true},
  "ean13":{"enable":true,"supported":true},
  "ean8":{"enable":true,"supported":true},
  "gs1DataBar_14":{"enable":true,"supported":true},
  "gs1DataBar_Expanded":{"enable":true,"supported":true},
  "gs1DataBar_Limited":{"enable":true,"supported":true},
  "interleaved25":{"enable":true,"supported":true},
  "matrix25":{"enable":false,"supported":true},
  "maxicode":{"enable":false,"supported":true},
  "microQr":{"enable":false,"supported":true},
  "micropdf417":{"enable":false,"supported":true},
  "msi":{"enable":false,"supported":true},
  "p4State":{"enable":false,"supported":true},
  "pAus":{"enable":false,"supported":true},
  "pJap":{"enable":false,"supported":true},
  "pKix":{"enable":false,"supported":true},
  "pPlanet":{"enable":false,"supported":true},
  "pPostnet":{"enable":false,"supported":true},
  "pRM":{"enable":false,"supported":true},
  "pdf417":{"enable":true,"supported":true},
  "qrCode":{"enable":true,"supported":true},
  "upcA":{"enable":true,"supported":true},
  "upcE":{"enable":true,"supported":true}
}
Example
properties : any = {};
...
scannerProperties.edit(
  (data) => {
    this.properties =  JSON.parse(data);
    this.aztec = false;
    this.codabar = false;
    this.code128 = true;
    this.keyboardWedge = false;
  },
  (err) => { alert(err); }
);

.store(properties, successCallback, errorCallback): Object

Apply changes to one or more symbologies with the values supplied in properties.

Response

string with success message

Examples

Enable UPC-E symbology

scannerProperties.store({"upcE":{"enable":true,"supported":true}}, null, null);

Disable keyboard wedge feature

scannerProperties.store({"keyboardWedge":{"enable":false}}, null, null);

版本与发布记录

@datalogic/cordova-plugin-datalogic 共发布 11 个版本,首次发布于 2018/11/30;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.4.1latest2019/08/277 年前
0.4.02019/08/137 年前
0.3.02019/05/047 年前
0.2.52019/05/047 年前
0.2.42019/03/127 年前
0.2.32018/12/137 年前

关于 @datalogic/cordova-plugin-datalogic 的常见问题

@datalogic/cordova-plugin-datalogic 是什么?

Datalogic Cordova SDK for Android devices

如何安装 @datalogic/cordova-plugin-datalogic?

在项目目录运行 npm install @datalogic/cordova-plugin-datalogic,或使用 pnpm add / yarn add / bun add。

@datalogic/cordova-plugin-datalogic 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/datalogic__cordova-plugin-datalogic 是否存在。

@datalogic/cordova-plugin-datalogic 可以商用吗?

@datalogic/cordova-plugin-datalogic 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@datalogic/cordova-plugin-datalogic 的下载量有多少?

根据 npm 官方下载统计,@datalogic/cordova-plugin-datalogic 在 2026/10/12 – 2026/11/10 这 30 天内被下载 3,350 次,日均约 112 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@datalogic/cordova-plugin-datalogic 还在维护吗?

最新版本 0.4.1 发布于 2019/08/27(7 年前);至今共发布 11 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/11/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。