【发布时间】:2020-10-08 18:25:36
【问题描述】:
我正在开发 QR 码扫描应用程序。我正在使用 Barcode Detector 读取 QR 码,结果存储在 SparseArray 中。所以我的问题是我可以将 SparseArray 转换为 String 吗?这样我就可以使用 Split 函数打破字符串,然后将其与另一个字符串进行比较。
@Override
public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> qrcodes = detections.getDetectedItems();
if (qrcodes.size() != 0) {
txtResult.post(new Runnable() {
@Override
public void run() {
Vibrator vibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(100);
txtResult.setText(qrcodes.valueAt(0).displayValue);
}
});
}
}
【问题讨论】:
-
sparseArray.toString()。还是你的意思是别的?另外,为什么从集合中构建一个字符串只是为了将其拆分回一个集合?这似乎没用。 -
你想做什么?您的
SparseArray不包含字符串,它包含Barcodes。请解释您要“比较”的内容? -
所以 QR 包含一个带有数字的 url,由 ';' 分隔。我正在尝试拆分它并将二维码中的网址与我必须的网址进行比较。
标签: java android qr-code barcode