Reputation: 9
I have the following code in my android qr code scanner how do I change it so it redirects to an URL instead?
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == BARCODE_READER_REQUEST_CODE) {
if (resultCode == CommonStatusCodes.SUCCESS) {
if (data != null) {
val barcode = data.getParcelableExtra<Barcode>(BarcodeCaptureActivity.BarcodeObject)
val p = barcode.cornerPoints
mResultTextView.text = barcode.displayValue
} else
mResultTextView.setText(R.string.no_barcode_captured)
} else
Log.e(LOG_TAG, String.format(getString(R.string.barcode_error_format),
CommonStatusCodes.getStatusCodeString(resultCode)))
} else
super.onActivityResult(requestCode, resultCode, data)
}
Upvotes: 1
Views: 1374
Reputation: 553
You get the value inside the QR with:
barcode.displayValue
If is an URL and you want to redirect it, what you can do is add this code:
String url = barcode.displayValue;
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
Upvotes: 1