fhk 231
fhk 231

Reputation: 11

how to Automatically open the url that is scan from the qr code?

im creating an android app to scan qr code and redirect into that url automatically. now i have an app which scans the qr code and displays a pop up of the url with a "visit" button..when clicked will redirect me to that url .But i want to skip that pop up process and let me scan the qr code and automatically goes to that url without any pop up in between. what modification should i do . please say in simple terms since i dont know much coding.

this is the code for handling the result

@Override
public void handleResult(Result result) {
    final String myResult = result.getText();
    Log.d("QRCodeScanner", result.getText());
    Log.d("QRCodeScanner", result.getBarcodeFormat().toString());

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Scan Result");
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            scannerView.resumeCameraPreview(MainActivity.this);
        }
    });
    builder.setNeutralButton("Visit", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myResult));
            startActivity(browserIntent);
        }
    });
    builder.setMessage(result.getText());
    AlertDialog alert1 = builder.create();
    alert1.show();
}

}

Upvotes: 0

Views: 5763

Answers (1)

karan
karan

Reputation: 8853

Remove alert dialog code and call your intent directly inside method.

@Override
public void handleResult(Result result) {
    final String myResult = result.getText();
    Log.d("QRCodeScanner", result.getText());
    Log.d("QRCodeScanner", result.getBarcodeFormat().toString());
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myResult));
    startActivity(browserIntent);
}

Upvotes: 3

Related Questions