我用来扫描Qr Code Google Vison,但我有一点问题。扫描QR码时 它会自动为我保存几个对象。如何扫描QR码读取一个数据。
例如:
我的班级员工
模型对象员工
public class Employee {
private String firstName;
private String lastName;
private String age;
public Employee(String firstName, String lastName, String age) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
}
ScanQrCode.class
读取扫描Qr代码的方法
private ArrayList<Employee> employeeList = new ArrayList<Employee>();
...
//这个带有QR码读取值的方法
@Override
public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> barcodes = detections.getDetectedItems();
if (barcodes.size() != 0) text.post(new Runnable() {
@Override
public void run() {
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(400);
String name,lastname,age;
String[] dataEmployee = new String[3];
barcodeString = barcodes.valueAt(0).displayValue;
Pattern p = Pattern.compile("<z[0-9]>(.+?)</z[0-9]>");
if (p.matcher(barcodeString).matches()) {
Matcher m = p.matcher(barcodeString);
while (m.find()) {
dataEmployee[index] = m.group(1);
index++;
}
name = dataEmployee[0];
lastname = dataEmployee[1];
age = dataEmployee[2];
Employee empmoo = new Employee(name,lastname,age);
employeeList.add(empmoo);
}