0

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?

Gowthaman M
  • 8,057
  • 8
  • 35
  • 54

1 Answers1

0

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);
}}
Zaid Mirza
  • 3,540
  • 2
  • 24
  • 40
  • Thank you sir for the respond. I already tried the code, but it shows error like this: Error:Failed to complete Gradle execution. Cause: Unable to start the daemon process. This problem might be caused by incorrect configuration of the daemon. For example, an unrecognized jvm option is used. Please refer to the user guide chapter on the daemon at https://docs.gradle.org/4.1/userguide/gradle_daemon.html Please read the following process output to find out more: ----------------------- Error occurred during initialization of VM Could not reserve enough space for 1048576KB object heap – Ricardo F. Seikka Jan 21 '18 at 13:26
  • error you are telling is unrelated to change in answer – Zaid Mirza Jan 21 '18 at 13:32
  • I got a log that said "cannot resolve symbol 'SpannableString'". Same goes to linkify. – Ricardo F. Seikka Jan 21 '18 at 13:34
  • you have to Import class, Alt+Enter. These are very basic – Zaid Mirza Jan 21 '18 at 13:41
  • Nevermind its my RAM. But I already test the code, the result is still the same sir. I can't click on the result link. It didn't direct me to the link url from the result. – Ricardo F. Seikka Jan 21 '18 at 14:41