The Scandit SDK supports add-on codes (also known as Extension Codes) for EAN-8, EAN-13, UPC-A and UPC-E codes. These codes encode additional product data like an issue number, date or price. There is a two (EAN-2/two-digit add-on) and a five digit (EAN-5/five-digit add-on) version.
Enable add-on codes in the SDK
- Enable both the main symbologies (e.g. EAN-13) and the add-on symbology (e.g. two-digit add-on) that you want to scan.
- Set the number of codes to scan in a frame to 2.
Accumulate scan results until two codes were scanned that fulfill the following conditions:
- One corresponds to the main symbology
- The other one corresponds to a symbology extension
The data of the two scanned codes is then returned as two separate results. Be aware that it can happen that only the main code is found in a particular frame. Isolated extension codes are never returned as a result.
Android
Settings setup for EAN-13 codes with a 5 digit add-on on Android:
ScanSettings settings = ScanSettings.create();
settings.setSymbologyEnabled(Barcode.SYMBOLOGY_EAN13, true);
settings.setSymbologyEnabled(Barcode.SYMBOLOGY_FIVE_DIGIT_ADD_ON, true);
settings.setMaxNumberOfCodesPerFrame(2);
settings.setCodeDuplicateFilter(0);
settings.setCodeCachingDuration(0);
BarcodePicker picker = new BarcodePicker(this, settings);
The Add-On code and the main code (EAN13, EAN8, UPCA, or UPCE) are returned as two separate codes and the result needs to be combined in the didScan callback. A possible implementation of the didScan callback can look like this:
@Override
public void didScan(ScanSession session) {
session.pauseScanning();
List<Barcode> codes = session.getNewlyRecognizedCodes();
Barcode addOnCode = null;
Barcode otherCode = null;
for (Barcode code : codes) {
if (code.getSymbology() == Barcode.SYMBOLOGY_FIVE_DIGIT_ADD_ON ||
code.getSymbology() == Barcode.SYMBOLOGY_TWO_DIGIT_ADD_ON) {
addOnCode = code;
} else {
otherCode = code;
}
}
String data;
if (addOnCode != null && otherCode != null) {
data = String.format("%1$s-%2$s", otherCode.getData(), addOnCode.getData());
} else {
data = otherCode.getData();
}
}
iOS
Settings setup for EAN-13 codes with a 5 digit add-on on iOS:
NSSet *symbologiesToEnable = [NSSet setWithObjects:
@(SBSSymbologyEAN13) ,
@(SBSSymbologyFiveDigitAddOn), nil];
[settings enableSymbologies:symbologiesToEnable];
settings.maxNumberOfCodesPerFrame = 2;
settings.codeDuplicateFilter = 0;
settings.codeCachingDuration = 0;
picker = [[SBSBarcodePicker alloc] initWithSettings:settings];
The Add-On code and the main code (EAN13, EAN8, UPCA, or UPCE) are returned as two separate codes and the result needs to be combined in the didScan callback. A possible implementation of the didScan callback can look like this:
- (void)barcodePicker:(SBSBarcodePicker *)picker
didScan:(SBSScanSession *)session {
SBSCode *addOnCode = nil;
SBSCode *otherCode = nil;
NSArray* recognized = session.newlyRecognizedCodes;
for (SBSCode *code in recognized) {
if (code.symbology == SBSSymbologyTwoDigitAddOn ||
code.symbology == SBSSymbologyFiveDigitAddOn) {
addOnCode = code;
} else {
otherCode = code;
}
}
NSString *data = nil;
if (addOnCode != nil && otherCode != nil) {
data = [NSString stringWithFormat:@"%@ - %@", otherCode.data, addOnCode.data];
} else {
data = otherCode.data;
}
}