Tabish Tanseef
Tabish Tanseef

Reputation: 57

How to make plain text which appears after scanning a QR clickable and redirects the user to the browser?

I have written a piece of code for scanning QR code. But after scanning it is showing the data in plain text even if it is a link or URL to some website. I want it to redirects the user to the particular website after scanning directly in the browser.

public void handleResult(Result rawResult) {
        // Do something with the result here
       // Log.v("tag", rawResult.getText()); // Prints scan results
       // Log.v("tag", rawResult.getBarcodeFormat().toString()); 
// Prints the scan format (qrcode, pdf417 etc.)

        MainActivity.tvresult.setText(rawResult.getText());
        onBackPressed();

        // If you would like to resume scanning, call this method below:
        //mScannerView.resumeCameraPreview(this);
    }

Upvotes: 0

Views: 452

Answers (2)

Skizo-ozᴉʞS ツ
Skizo-ozᴉʞS ツ

Reputation: 20646

Put this attribute to your TextView

<Textview 
          android:autoLink="web"/>

Other option is to create an Intent for that when user click on your TextView

Uri uri = Uri.parse(rawResult.getText());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent)

Better way also can be create a Linkify

Linkify.addLinks(tvresult, Linkify.WEB_URLS);

You can choose what you want.

Upvotes: 1

Elmira Frhn
Elmira Frhn

Reputation: 320

Make a TextView which you are showing text in it clickable in .xml file:

<Textview 
android:autoLink="web"
android:linksClickable="true"/>

Upvotes: 1

Related Questions