Alouini Khalil
Alouini Khalil

Reputation: 675

Serial scan using Zxing library - android

i'm developing a scan Barcode app on android , my application is simple and composed from an activity which contains a button and a textView which will receive the result of the scan..
The app works well but i want that i could realise serial scan in a raw. so after scanning a barcode i need that the capture Activity stay and the appli don't back to the button activity so i can scan the next Barcode. any solution please ? this is my main java code :

public class MainActivity extends Activity {
    private Button scan;

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);

   scan= (Button)findViewById(R.id.btnScan);

   scan.setOnClickListener(new View.OnClickListener() {

       @Override
       public void onClick(View v) {
           // TODO Auto-generated method stub  
           Intent intent = new Intent("com.google.zxing.client.android.SCAN");
           intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
           startActivityForResult(intent, 0);
       }
   });
}


public boolean onTouchEvent(final MotionEvent event) {

    IntentIntegrator integrator = new IntentIntegrator();
    integrator.initiateScan(null);

    return true;
    }

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

   super.onActivityResult(requestCode, resultCode, data);
   if (requestCode == 0) {
       if (resultCode == RESULT_OK) {

               String contents = data.getStringExtra("SCAN_RESULT");
               TextView tv = (TextView) findViewById(R.id.scanResult);
               tv.setText(data.getStringExtra("SCAN_RESULT"));//this is the result
       } else 

       if (resultCode == RESULT_CANCELED) {

         // Handle cancel

   } }
}
@Override
public void onConfigurationChanged(Configuration newConfig){        
   super.onConfigurationChanged(newConfig);
}
}

Upvotes: 1

Views: 451

Answers (2)

Alouini Khalil
Alouini Khalil

Reputation: 675

i finally found the solution i had just to add this code in the onActivityResult() declaration

           Intent intent = new Intent("com.google.zxing.client.android.SCAN");
           intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE",              "QR_CODE_MODE");
           startActivityForResult(intent, 0);

So after the scan is finished the app is ready to scan again instead of going back to the home activity

Upvotes: 0

axl coder
axl coder

Reputation: 749

I had the same problem when I did my scanner activity, and the solution that I found was to make my mainActivity extends Zxing CaptureActivity, like this I overrided handleDecode and I avoided to switch between different activities (as you have to do to obtain your scanner result).

Anyhow, to restart the scanning process after a precedent scan I called the method

  restartPreviewAfterDelay(0L)

(that is a method of CaptureActivity) in the onClick function of a button.

Take a look at that method, I think that it is what you need.

Upvotes: 1

Related Questions