Android Xzing library (read barcode) with fragment

Question:

My application worked perfectly with Zxing, after implementing fragment, barcode reading stopped working. I tried to configure the return on fragment, on activity… but I was unsuccessful. Has anyone managed to do this implementation?

Answer:

Call:

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

Reception:

    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 it works perfectly!

Scroll to Top