Barcode is widely used nowadays, not just for scanning items at supermarket, but can be used to scan any other information such as identity info, tracking info and many more, which are generally referred to as Automatic Identification and Data Capture (AIDC).
Crosslight provides a service that allows you to scan barcode types easily with fast response. This barcode scanner service also comes with configurable build-in user interface, so you can enable barcode scanner functionally in your application with just few line of codes.
Configuring Project Reference
To use the barcode scanner service, simply add the following NuGet packages to your project:
- Intersoft.Crosslight.Services.Barcode. This package supports cross-platform projects and should be targeted to the Core project and all platform-specific projects in your solution.
For more information on using NuGet in Xamarin Studio and Visual Studio, see Introduction to Crosslight NuGet Packages and Walkthrough: Working with Crosslight NuGet Packages.
Add Barcode Reader PreserveAssembly Configuration
On each platform, Crosslight has AppInitializer.cs which is useful to initialize platform-specific functions. During build process, the linker of Xamarin SDK will remove unused class references, including Barcode Reader class reference. To prevent the Xamarin SDK from removing the references, you will need to add an additional configuration in InitializeServices method of AppInitializer class such as shown in the following. The configuration for each platform is as simple as:
By adding this configuration, Xamarin SDK will treat SQLite class reference as in-used, so the SQLite will now run well.
Using Barcode Reader Service
To use the barcode reader service, you will need to enable camera permission in your devices. On iOS, the app will prompt you to allow the app to use the camera feature, as for Android, you need to set it in AndroidManifest.xml file.
Invoking the Barcode Scanner
You can simply resolve the BarcodeReaderService and execute the Scan method as follows.
This will open a new user interface that allows you to scan barcode using the phone's camera. It will try to determine the barcode with all possible built-in decoders that are available in the Crosslight barcode reader service.
Scanning Specific Barcode Types
Alternatively, you can configure which barcode types that the service will use by specifying the barcode type in the Scan method as follows.
You can also change other configuration in barcode reader such as InitialDelayBeforeAnalyzingFrames, DelayBetweenAnalyzingFrames and AutoRotate that available at MobileBarcodeScanningOptions. You can then passed this configurable options to the Scan method as follows.
Supported Barcode Types
The following list shows the barcode types that Crosslight barcode reader service supports.
UPC EAN Extension
To see the barcode reader service in action, check out the Barcode Reader sample here.