简体   繁体   中英

QR Code Scanner result can't be click

I got a problem with my scanner app that I just build using android-studio 3.0. When it scanning, the result url can't be click.

MainActivity.java:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mScannerView = new ZXingScannerView(this);
    setContentView(mScannerView);
}
@Override
public void onResume() {
    super.onResume();
    mScannerView.setResultHandler(this);
    mScannerView.startCamera();
}

@Override
public void onPause() {
    super.onPause();
    mScannerView.stopCamera();
}

@Override
public void handleResult(Result rawResult) {
    Log.v("TAG", rawResult.getText()); // Prints scan results
    Log.v("TAG", rawResult.getBarcodeFormat().toString());
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Scan Result");
    builder.setMessage(rawResult.getText());
    AlertDialog alert1 = builder.create();
    alert1.show();

    mScannerView.resumeCameraPreview(this);
}}

Can someone help me fix this?

You have to make your text linkify, please try below code. I have not tested it but it should work

@Override
public void handleResult(Result rawResult) {
// Linkify the message
    final SpannableString s = new SpannableString(rawResult.getText());
    Linkify.addLinks(s, Linkify.ALL);

    Log.v("TAG", rawResult.getText()); // Prints scan results
    Log.v("TAG", rawResult.getBarcodeFormat().toString());
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Scan Result");
    builder.setMessage(s);
    AlertDialog alert1 = builder.create();
    alert1.show();

    mScannerView.resumeCameraPreview(this);
}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM