Android Vision Api - Barcode Detection How To Get Type Of Barcode?
I am working with Android Google Vision API, and have created a standard barcode reader, but I want to detect what type/format of barcode is read i.e. CODE 39, CODE 128, QR Code...
Solution 1:
Because I does not found any bulid-in function to decode Format integer value to text value I used following custom method
private String decodeFormat(int format) {
switch (format){
case Barcode.CODE_128:
return"CODE_128";
case Barcode.CODE_39:
return"CODE_39";
case Barcode.CODE_93:
return"CODE_93";
case Barcode.CODABAR:
return"CODABAR";
case Barcode.DATA_MATRIX:
return"DATA_MATRIX";
case Barcode.EAN_13:
return"EAN_13";
case Barcode.EAN_8:
return"EAN_8";
case Barcode.ITF:
return"ITF";
case Barcode.QR_CODE:
return"QR_CODE";
case Barcode.UPC_A:
return"UPC_A";
case Barcode.UPC_E:
return"UPC_E";
case Barcode.PDF417:
return"PDF417";
case Barcode.AZTEC:
return"AZTEC";
default:
return"";
}
}
Solution 2:
Found it in the documentation (missed it previously). https://developers.google.com/android/reference/com/google/android/gms/vision/barcode/Barcode
Using
format
you can get the barcode type this is retuned as an integer.
Solution 3:
valueFormat returns the type, it can match the static variables of the API. Example:
final SparseArray <Barcode> barcodes = detections.getDetectedItems ();
if (barcodes.size ()! = 0) {
txtBarcodeValue.post (new Runnable () {
@Override
publicvoidrun () {
System.out.println ("barcodes");
System.out.println (barcodes.valueAt (0) .format); // 256
System.out.println (barcodes.valueAt (0) .valueFormat); // 1 or 2 or 3 ....
......
.
and the codes you can find them in the class Barcode.class
publicstaticfinalintCONTACT_INFO=1;
publicstaticfinalintEMAIL=2;
publicstaticfinalintISBN=3;
publicstaticfinalintPHONE=4;
publicstaticfinalintPRODUCT=5;
publicstaticfinalintSMS=6;
publicstaticfinalintTEXT=7;
publicstaticfinalintURL=8;
publicstaticfinalintWIFI=9;
publicstaticfinalintGEO=10;
Post a Comment for "Android Vision Api - Barcode Detection How To Get Type Of Barcode?"