Search code examples
androidzxing

Android: Zxing barcode lib parse a string to BarcodeFormat


I am using zxing barcode lib for decoding barcodes in my application. I successfully gets the ISBN from the barcode on activityresult. However i also needs to get the barcode type so i added another parameter that is getBarcodeFormat() in the return intent as extras. an excerpt of the code is below

 Intent intent = new Intent();
        intent.putExtra("ISBN", rawResult.getText());
        intent.putExtra("BarCodeType",rawResult.getBarcodeFormat());
        setResult(RESULT_OK,intent);

On my actual activity i gets the barcodeformat in string format but i need it to parse into BarcodeFormat object since i need to again covert the isbn to barcode using

writer.encode(contentsToEncode, format, img_width, img_height, hints);

method which accepts the BarcodeFormat object instead of string format. I couldn't find any method in BarcodeFormat documentation. If anyone has the solution to it, kindly share. I'll be really thankful to you


Solution

  • Found the solution. Following method worked for me,

    BarcodeFormat format=BarcodeFormat.valueOf(BarCodeType);
    

    Previously i used the wrong string so was getting the exception.