Intercept barcode scanning event

僤鯓⒐⒋嵵緔 提交于 2020-02-23 08:10:13

问题


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.


回答1:


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

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

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

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);
    }
}


}


来源:https://stackoverflow.com/questions/45435877/intercept-barcode-scanning-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!