android – Why ZXing does not detect QRcode from camera in emulator?-ThrowExceptions

Exception or error:

I am making small program for reading QR code using ZXing, following this video:

https://www.youtube.com/watch?v=NqFVqLqbw_g

and using this repository:

https://github.com/journeyapps/zxing-android-embedded

My code looks like this:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
/// scan with zxing: https://www.youtube.com/watch?v=NqFVqLqbw_g
    public void btnScanHandler(View view) {
         IntentIntegrator scanner = new IntentIntegrator(this); // `this` is the current Activity
         scanner.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE);
         scanner.initiateScan();

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
            if(result != null) {
                if(result.getContents() == null) {
                    Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
                }
            } else {
                super.onActivityResult(requestCode, resultCode, data);
            }
        }
    }
}

My target API version is 28.

But for some reason a qr code is not detected after I start this code in emulator:

QR code is clearly visible but not detected

QR code is visible clearly, but not detected. Toast with text is not shown. Why may this happen?

Update: I uploaded a program to my phone and it works great. But I’d like to work with emulator, to avoid possible failures with phone.

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *