Last active
July 18, 2018 07:07
-
-
Save elvismetaphor/4795f0c8410cbb8d8a169b593105620b to your computer and use it in GitHub Desktop.
Add on-device barcode scanner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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