Java – Use zxing in Android applications to scan barcode reader data

Use zxing in Android applications to scan barcode reader data… here is a solution to the problem.

Use zxing in Android applications to scan barcode reader data

This is my code that doesn’t work for me

 public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("", "QR_CODE_MODE");
                startActivityForResult(intent, 0);

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");

             Handle successful scan
        } else if (resultCode == RESULT_CANCELED) {
             Handle cancel

startActivityForResult(intent, 0) error; I don’t know how to fix this error, please help me


You can also do this by extending CaptureActivity.

 public void onClick(View v) {
   Intent intent=new Intent(A.this,ScannerActivity.class);

Scanner Activity:

public class ScannerActivity extends CaptureActivity {

/** The barcode format. */
String barcodeFormat;

 * Called when the activity is first created.
 * @param savedInstanceState
 *            the saved instance state
public void onCreate(Bundle savedInstanceState) {

 * (non-Javadoc)
 * @see
 * .zxing. Result,
public void handleDecode(Result rawResult, Bitmap barcode) {

String barcodeType = rawResult.getBarcodeFormat().toString();
    String productId = rawResult.getText();
 Toast.makeText(getApplicationContext(),"Contents"+productId +"Format"+barcodeType ,Toast.LENGTH_LONG).show();
    handle intent by sending product id as your wish...


barcode_scan.xml: (Don’t forget to include capture.xml).

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android=""
   android:orientation="vertical" >
    <include layout="@layout/capture"/> 

Related Problems and Solutions