Android Xzing library (read barcode) with Fragment

Asked

Viewed 585 times

3

My application worked perfectly with Zxing, after implementing Fragment, the barcode reading stopped working. I tried to configure the return in Fragment, in Activity... but I was unsuccessful. Someone managed to do this implementation?

1 answer

2


Calling for:

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

Receiving:

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

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


        }
        else if (resultCode == Activity.RESULT_CANCELED){
            Toast.makeText(getActivity(), "Scan unsuccessful", Toast.LENGTH_SHORT).show();

        }
    }
}

Here works perfectly!

  • Thiago, are you making this call inside the Fragment? What version of Zxing are you using? Vlw for help.

  • 2

    Version: zxing-android-minimal:1.2.1. Exactly, I do inside a Fragment. By clicking a button it called inside an Onclicklistener, which is on an android.app.Fragment

  • 1

    Thiago, I will test and return. Thanks for the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.