简体   繁体   English

在Android应用中使用内置条形码扫描仪

[英]Using built-in barcode scanner in an Android app

I'm building an app that among other features should be able to scan different barcodes and process the information obtained. 我正在构建一个应用程序,该应用程序除其他功能外应能够扫描不同的条形码并处理获得的信息。 The device, this app will be running on(Honeywell CT50) has a built-in scanner. 该设备将在具有内置扫描仪的(Honeywell CT50)上运行。 I am aware of ZXing but for this app, it is necessary to be able to use the built-in scanner because it is much faster and easier to handle. 我知道ZXing,但是对于此应用程序,必须能够使用内置扫描仪,因为它更快,更容易处理。

My question is how to properly integrate such a built-in scanner in my app. 我的问题是如何在我的应用程序中正确集成这样的内置扫描仪。 When the scanner reads a barcode, the corresponding numbers will always be sent to whatever the device is currently doing. 当扫描仪读取条形码时,相应的号码将始终发送到设备当前正在执行的操作。 This means that for example if I create a textfield and set the focus to it, as soon as I scan something, the numbers will be copy-pasted right into this textfield, meaning that I do not need to somehow programmatically access the scanner. 这意味着,例如,如果我创建一个文本字段并将焦点设置到该文本字段,则在我扫描某些内容时,这些数字将被直接复制粘贴到该文本字段中,这意味着我无需以某种方式以编程方式访问扫描仪。 However, this also means that my app will not know when something has been scanned successfully. 但是,这也意味着我的应用程序将不知道何时成功扫描了某些内容。 I want to prevent, having an OK button next to this textfield so I need to tell the app when it should start processing the data entered. 我想防止此文本字段旁边有一个确定按钮,因此我需要告诉应用程序何时应开始处理输入的数据。 I can not do this via a TextChangedListener because basically, the device pastes number by number of the barcode into the textfield instead of pasting the whole thing at once so the event would execute right after the first digit. 我无法通过TextChangedListener做到这一点,因为从根本上说,设备会将条码的数字粘贴到文本字段中,而不是一次粘贴整个内容,因此事件将在第一个数字之后立即执行。

I know that it is possible (at least on this device) to define a prefix and a suffix for the built-in scanner so I could for example tell it to always push the ENTER key each time a barcode is read and filter this by using a TextChangedListener. 我知道可以(至少在此设备上)为内置扫描仪定义前缀和后缀,因此,例如,我可以告诉它每次读取条形码时始终按ENTER键,并使用进行过滤TextChangedListener。 The problem with this is that there are other pre-installed apps on this device too which will not work properly if changes like this are made so unfortunately, this is not an option. 问题是该设备上还有其他预安装的应用程序,如果不幸进行了此类更改,这些应用程序也将无法正常运行,这不是一种选择。

All in all I'm not even sure if I'm approaching this in the right way. 总而言之,我什至不确定我是否以正确的方式来解决这个问题。 It seems like it would be required that I somehow catch certain events fired by the built-in scanner in the program code of my app but I do not know how. 似乎需要以某种方式在我的应用程序的程序代码中捕获内置扫描仪触发的某些事件,但我不知道如何。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM