我的扫描仪应用程序出了问题,我只是使用android-studio 3.0构建。扫描时,结果网址无法点击。
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);
}}
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
您必须将文字链接,请尝试以下代码。我没有测试它但它应该工作
@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);
}}