3

I've been trying to get this library to work in my android app, but I can't get it to work successfully. I have the fragment showing and the camera shows fine, but it doesn't seem to scan anything (QR, Barcodes etc). I've implemented the call back interface and still nothing happens.

If anyone could give a small example of how to set up the library to scan product codes (code 128) it would be a massive help!

Also, I've already looked at other related questions (here and here) and I still can't get it to work.

Thanks

Community
  • 1
  • 1
derpyderp
  • 926
  • 1
  • 10
  • 15

4 Answers4

2

I've just released a library to help with that. It's inspired by the library you mentioned, but I needed compatibility with Android 2.1+. I hope it helps.

Link: https://github.com/welcu/zxingfragmentlib

mitoyarzun
  • 101
  • 5
2

The library that you reffered has been depricated. please use https://code.google.com/p/barcodefraglibv2/

Abhinava
  • 1,030
  • 9
  • 19
0
buttonScan = (Button) view.findViewById(R.id.button_imei_scan);
buttonScan .setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                 Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                    intent.putExtra("SCAN_MODE", "BAR_CODE_MODE");
                    startActivityForResult(intent, 0);
            }
        });

@Override
    public void  onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == 0) {
           if (resultCode == getActivity().RESULT_OK) {

              String contents = intent.getStringExtra("SCAN_RESULT");
              String format = intent.getStringExtra("SCAN_RESULT_FORMAT");

              Toast.makeText(getActivity(),"SCAN_RESULT --- >>>   " + contents , 
                      Toast.LENGTH_LONG).show();
              // Handle successful scan

           } else if (resultCode == getActivity().RESULT_CANCELED) {
              // Handle cancel
              Log.i("App","Scan unsuccessful");
           }
      }
   }
  • Thank you for your answer. But: Why should the OP try this code? A **good answer** will always have an explanation of what was done and why it was done in such a manner, not only for the OP but for future visitors to SO. – B001ᛦ Sep 02 '16 at 09:41
0

you can implement ZXingScanner into Fragment.

Official Documnent

https://github.com/dm77/barcodescanner/blob/master/zxing-sample/src/main/java/me/dm7/barcodescanner/zxing/sample/FullScannerFragment.java

Download source code using this link

https://github.com/mitoyarzun/zxingfragmentlib

Keshav Gera
  • 10,807
  • 1
  • 75
  • 53