拦截条形码扫描事件 [英] Intercept barcode scanning event

查看:134
本文介绍了拦截条形码扫描事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序将通过集成的条形码扫描仪安装在移动设备中. 在我的页面中,有不同类型的小部件,包括一个不可见的条目,我想使用它临时存储扫描的条形码值. 问题在于用户可以点击页面中的所有窗口小部件并与之交互,并且在未知的时刻,他可以扫描条形码. 我想将焦点置于此不可见的条目中或拦截键入的文本(因为条形码扫描就像键盘键入一样).我该怎么做? 我正在使用Xamarin.Forms和用于MVVM的Prism框架进行开发.

I'm developing an application that will be installed in mobile devices with integrated barcode scanner. In my page there are different types of widget, included a not visible Entry that I want to use temporary to store the scanned barcode value. The problem is that the user can tap and interact with all the widgets in the page and, in an unknown moment, he can scan a barcode. I want to force the focus in this invisible Entry or intercept the text typed (because a barcode scan is like a keyboard typing). How I can do that? I'm developing with Xamarin.Forms with Prism framework for MVVM.

=条形码不与凸轮一起扫描.

N.B. = The barcode scanning is not with the cam.

推荐答案

使用键盘仿真"从扫描仪读取条形码不是一个好主意.我不知道您使用的是什么(通过蓝牙连接的外部条形码读取器,集成的条形码读取器),但是通常,您不应该具有带有Focus的条目来读取从扫描仪接收到的字符串.

It's not a good Idea to use "Keyboard emulation" to read barcode from scanner. I don't know what are you using (an external barcode reader connected via bluetooth, an integrated barcode reader) but usully you should not have an Entry with a Focus to read a string received from a scanner.

如果您正在使用通过蓝牙连接的外部条形码阅读器,建议阅读

If you are using an external barcode reader connected via bluetooth, I suggest to read this article

否则,如果您使用集成扫描仪(如TC51 Zebra设备),则应使用SDK.

Otherwise, if you are using an integrated scanner (like TC51 Zebra device) you should use the SDK.

如果您使用的是TC51,则可以在此处找到用于Xamarin的SDK 此处示例如何在Xamarin.Android中使用它.

If you are using TC51, you can find here the SDK for Xamarin and here a sample how to use it in Xamarin.Android.

如果必须在Xamarin Forms中进行测试,则必须执行与Xamarin.Android相同的操作,并在收到条形码时,通过MessagingCenter将其发送到XF应用程序

If you have to test in in Xamarin Forms, you have to do the same thing you are doing with Xamarin.Android and when you receive a barcode, send to your XF app with a MessagingCenter

void scanner_Data(object sender, Scanner.DataEventArgs e)
{
    ScanDataCollection scanDataCollection = e.P0;

if ((scanDataCollection != null) && (scanDataCollection.Result == ScannerResults.Success))
{
    IList<ScanDataCollection.ScanData> scanData = scanDataCollection.GetScanData();

    foreach (ScanDataCollection.ScanData data in scanData)
    {
        displaydata(data.LabelType + " : " + data.Data);

        // Something like this
        Xamarin.Forms.MessagingCenter.Send<App> ((App)Xamarin.Forms.Application.Current, "Barcode", data.Data);
    }
}


}

这篇关于拦截条形码扫描事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆