Show the scanner

You can use our samples to get a good overview of how to show the barcode scanner in an app: Run the samples.

The scan view itself (BarcodePicker) is a RelativeLayout and therefore a normal view in Android. You can add it to the view hierarchy like any other view and add further views on top of the overlay view or the picker itself.


Displaying the scan view in fullscreen

To display the scan view in fullscreen the best option is to open an Activity for it and set the barcode picker as the content view.

// Set app key. This will only have to be done once
ScanditLicense.SetAppKey("yourAppKey");
// Create the scan view. Note that you will have to configure the settings since the
// default settings have all symbologies disabled and you won't be able to scan anything.
BarcodePicker barcodePicker = new BarcodePicker(context, ScanSettings.Create());
// Add scan view as the activity's root view
SetContentView(picker);


Adding the scan view as a subview

As the BarcodePicker is a normal RelativeLayout you can add it to your own layout like any other view:

// Set app key. This will only have to be done once
ScanditLicense.SetAppKey("yourAppKey");
// Create the scan view. Note that you will have to configure the settings since the
// default settings have all symbologies disabled and you won't be able to scan anything.
BarcodePicker barcodePicker = new BarcodePicker(context, ScanSettings.Create());
// Add the scan view to the root view.
rootView.AddView(barcodePicker);


Scaling and/or Cropping the subview

To scale and/or crop the scan view you only need to change its width and height. Here is a small example of scaling the scan view to 3/4 of its width and 1/2 of its height (meaning 1/12 of its height will be cropped at the top and 1/12 at the bottom):

// Set app key. This will only have to be done once
ScanditLicense.SetAppKey("yourAppKey");
// Create the scan view. Note that you will have to configure the settings since the
// default settings have all symbologies disabled and you won't be able to scan anything.
BarcodePicker barcodePicker = new BarcodePicker(context, ScanSettings.Create());
// Get the device's display for width and height.
IWindowManager wm = (IWindowManager)GetSystemService (Context.WindowService);
Display display = wm.DefaultDisplay;
// Create layout parameters to scale it to 3/4 of its size.
RelativeLayout.LayoutParams rParams = new RelativeLayout.LayoutParams(
display.Width * 3 / 4, display.Height / 2);
rParams.AddRule(LayoutRules.CenterHorizontal);
// Add the scan view to the root view.
rootView.AddView(barcodePicker, rParams);