Using ZBar (Android) SDK, My Application Is Getting Different ISBNs From The Same Book Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Using ZBar (Android) SDK, My Application Is Getting Different ISBNs From The Same Book without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am creating an application that is using the ZBar SDK on Android to scan books and get their ISBN. I have gotten everything to work on the physical side. You press a button, the scanner window pops up and scans the bar code.

The problem comes when the application gets the ISBN from the scanner, it seems that the scanner is either reading the bar code incorrectly or that I am not pulling in the right data. Does anyone know how to fix this issue? Thanks. Below is relevant code, and a few screens

public void onClick(View v) 
    //TODO add functionallity
    if(v.getId() ==
        Intent intent = new Intent(this, ZBarScannerActivity.class);
        intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.ISBN10, Symbol.ISBN13, Symbol.EAN8, Symbol.EAN13 });
        startActivityForResult(intent, ZBAR_SCANNER_REQUEST);


protected void onActivityResult(int requestCode, int resultCode, Intent data)
    if (resultCode == RESULT_OK) 
        // Scan result is available by making a call to data.getStringExtra(ZBarConstants.SCAN_RESULT)
        // Type of the scan result is available by making a call to data.getStringExtra(ZBarConstants.SCAN_RESULT_TYPE)
        contentText.setText("ISBN: " + data.getStringExtra(ZBarConstants.SCAN_RESULT));
        Toast.makeText(this, "Scan Result = " + data.getStringExtra(ZBarConstants.SCAN_RESULT), Toast.LENGTH_SHORT).show();

        Toast.makeText(this, "Scan Result Type = " + data.getStringExtra(ZBarConstants.SCAN_RESULT_TYPE), Toast.LENGTH_SHORT).show();
        // The value of type indicates one of the symbols listed in Advanced Options below.
    else if(resultCode == RESULT_CANCELED) 
        Toast.makeText(this, "Scanning Cancelled", Toast.LENGTH_SHORT).show();

First Screen

Second Screen

Offending Bar Code


We have been using Zbar in production in one of our desktop applications. In this we extract the barcode from the Image and use it. Though it is different from yours but the issue is the same where we extract the barcode from live stream.

The issue you are facing is very prevalent and error prone. And ultimately all depends on the picture. (In fact you will observe the same behavior with Zxing, Eymbarcode and other open source ones. The most stable one I found is this). Ultimately we had to resort to Image taking guidelines. The below are the quality factors we use to avoid it:

The following factors determine the detection ability of the application:

  1. Resolution
  2. Focus
  3. Lighting and Exposure
  4. Noise

Hence it is essential that all the above four are taken care of while the picture is taken.

  1. Resolution: It would be desired that the barcode occupy significant portion on the Image. For long linear barcodes or dense 2-D symbols, one will probably have to increase the resolution. If the resolution decreases below two pixels, it will be hard to scan the barcode.

  2. Focus: Blurred Images are highly undesired. Even a portion of barcode consisting of blurry part will lead to inability of detection.

  3. Lighting and Exposure: An image that is too bright or overexposed can completely wash out any barcodes. An image that is too dark or underexposed will not provide sufficient contrast for the scanner. Low light levels also tend to produce noisier images.

  4. Noise: Random variation of brightness/color can make it difficult to scan the barcode.

  5. Angle: It would be preferred to have the barcode placed either horizontally or vertically placed.

  6. Tilt: It would be preferred if the camera is placed perpendicular to the image.

The above does not solve your problems, but I hope it helps

We are here to answer your question about Using ZBar (Android) SDK, My Application Is Getting Different ISBNs From The Same Book - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji