I integrated ZXing to a Xamarin.Forms project which enables user to scan barcode and put the received data into an Entry field. I tried it with 13-digit barcode and it always fails reading the first number "0" and receives the remaining 12 digits.
Barcodes start with other numbers work fine. I am now band-aiding the code by only accepting 13-digit number but that's not a "solution".
using ZXing.Net.Mobile.Forms;
async void ScanButtonClicked(object sender, EventArgs s)
{
var scanPage = new ZXingScannerPage()
await Navigation.PushAsync(scanPage);
scanPage.OnScanResult += (result) =>
{
scanPage.IsScanning = false;
Device.BeginInvokeOnMainThread(async () =>
{
if (result != null && result.length == 13) // this is just a band-aid...
{
entry.text = result.Text;
}
});
};
}
How can I solve this?
The UPC-A is a subset of EAN-13, any EAN-13 start with 0 will be regarded as UPC-A, which is 12 digits without the leading 0.An EAN with a leading 0 is identical to a UPC code without that 0. It is returned as UPC. If you want the response to only be EAN-13 interpretations, set that as the only requested format like this:
var opts = new MobileBarcodeScanningOptions
{
PossibleFormats = new List<BarcodeFormat> { BarcodeFormat.EAN_13 }
};