如何从QR Code Scanner中获取结果URL?

时间:2018-01-28 03:41:52

标签: java android-studio qr-code barcode-scanner

我只是按照本教程视频: https://www.youtube.com/watch?v=Fe7F4Jx7rwo

在我们扫描QR码之后,它最终只显示一个文本,即使它是一个链接。如何将其从我的QR码放入的网址更改为可点击链接?

这是我在MainActivity中使用的代码:

private Button scan_btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    scan_btn = (Button) 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 NOW");
            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();
    super.onActivityResult(requestCode, resultCode, data);

        }
    }}}

0 个答案:

没有答案