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:

and using this repository:

My code looks like this:

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {
/// scan with zxing:
    public void btnScanHandler(View view) {
         IntentIntegrator scanner = new IntentIntegrator(this); // `this` is the current Activity


    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 *