Search code examples
androidzxingbarcode-scanner

Android barcode reading


I am developing a barcode scanning app and using Zxing as the barcode scanner. My app sends an intent to Zxing which fires up and allows me to scan a barcode but ... I can't get any data back. I don't the the barcode numbers returned to my app so I can use them in my code.

The following is my code:

public class ScaningActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);        

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

}//close onCreate
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
      IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
      if (scanResult != null) {
        // handle scan result
        Log.e("DATA", "TESTING SCAN RESULT : " + scanResult.toString());
      }else{
          Log.d("DATA", "NO SCAN RESULTS : ");// + scanResult.getFormatName());//scanResult.getContents());
      }
      // else continue with any other code you need in the method
      Log.i("DATA", "Continuing after scan result");
      Log.d("DATA", "requestCode : " + requestCode);
      Log.d("DATA", "resultCode : " + resultCode);
      Log.d("DATA", "intent : " + intent);
    }
}//close ScaningActivity

In the onActivityResult function, I get the NO SCAN RESULTS message.

What am I doing wrong?


Solution

  • Don't try to do this all yourself, because you are doing it wrong. In particular you are not sending the Intent correctly. Please also use IntentIntegrator for this.