Skip to content

Instantly share code, notes, and snippets.

@elvismetaphor
Last active July 18, 2018 07:07
Show Gist options
  • Save elvismetaphor/4795f0c8410cbb8d8a169b593105620b to your computer and use it in GitHub Desktop.
Save elvismetaphor/4795f0c8410cbb8d8a169b593105620b to your computer and use it in GitHub Desktop.
Add on-device barcode scanner
public void scanBarcode(Bitmap image) {
FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(image);
FirebaseVisionBarcodeDetectorOptions options =
new FirebaseVisionBarcodeDetectorOptions.Builder()
.setBarcodeFormats(
FirebaseVisionBarcode.FORMAT_QR_CODE,
FirebaseVisionBarcode.FORMAT_AZTEC
)
.build();
FirebaseVisionBarcodeDetector detector = FirebaseVision.getInstance()
.getVisionBarcodeDetector(options);
detector.detectInImage(image)
.addOnSuccessListener(new OnSuccessListener<List<FirebaseVisionBarcode>>() {
@Override
public void onSuccess(List<FirebaseVisionBarcode> barcodes) {
// Task completed successfully
// ...
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// Task failed with an exception
// ...
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment