如何将文本视图中显示的 QR 扫描详细信息传递或获取到字符串?

How to pass or get the QR Scan details showed in a text view to a string?

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
                if (data != null) {
                    final Barcode barcode = data.getParcelableExtra("barcode");
                    result.post(new Runnable() {
                        @Override`enter code here`
                        public void run() {
                            result.setText(barcode.displayValue);
                        }
                    }
                 }
            }
} 

// 上面是获取条码值到textview的对象(结果) //

Ctrl + 将鼠标悬停在 displayValue 上应该会显示它的类型。在 int/float/double/long 的情况下,您可以使用

String value = String.valueOf(barcode.displayValue);

如果是字符串,可以使用

String value = barcode.displayValue

在任何其他情况下,您可以使用

String value = barcode.displayValue.toString();

或者,要直接回答您的问题 - 要从 TextView 获取字符串,您可以使用

String value = textview.getText().toString();

其中 textViewTextView 的实例(在这种情况下,我想它是 result