mercredi 1 juillet 2020

QR Code verification for if-else statements

I am writing a code for a QR Code Scanner which scans only recognizes specific QR Codes and redirects to another activity. Here's the code

@Override
public void handleResult(Result result) {
    final String scanResult = result.getText();
    if (scanResult.equals("abcd")) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Scan");
        builder.setMessage("QR Code verified. Proceed?");
        builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Intent intent1 = new Intent(MainActivity.this, buttons.class);
                startActivity(intent1);
            }
        });
        builder.setNegativeButton("Close", null);
        
    }
    else {
        Toast.makeText(this, "unrecognized", Toast.LENGTH_LONG).show();
        scannerView.resumeCameraPreview(MainActivity.this);


    }
  }
}

The code works for the else statement, ie, if the result isn't "abcd", the Toast message is displayed.

But when the result is "abcd", the scanner freezes and the intent i have added, ie, buttons.class to be launched doesnt work (the activity doesnt start). The app is stuck on the scanned QR Code and doesnt move ahead. How do i fix that?

Aucun commentaire:

Enregistrer un commentaire