简体   繁体   中英

URL Result from QR Code Scanner

So I'm trying to build a QR Code Scanner, but my result only showing a text. Even the QR Code is have a URL link on it. It can't be open to a browser.

Here's my code for the scanner:

public class ReaderActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_reader);
    Button scan_btn = findViewById(R.id.scan_btn);
    final Activity activity = this;
    scan_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            IntentIntegrator integrator = new IntentIntegrator(activity);
            integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
            integrator.setPrompt("Scan");
            integrator.setCameraId(0);
            integrator.setBeepEnabled(false);
            integrator.setBarcodeImageEnabled(false);
            integrator.initiateScan();
        }
    });
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if (result != null) {
        if (result.getContents() == null) {
            Toast.makeText(this, "You cancelled the scanning", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(this, result.getContents(), Toast.LENGTH_LONG).show();
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);


    }
}}

What should I add or change to get clickable URL result? Can someone fix this? Please help me to get my project done. I really need it.

您将在result.getContents()上立即获得QR结果,您必须使用操作意图进行查看才能在浏览器中打开URL

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