Używam do skanowania kodu Google Qr Google Vison, ale mam mały problem. Podczas skanowania kodu QR automatycznie zapisuje mi się kilka obiektów. Jak zrobic zeby podczas skanowania QR kodu zapisało się jedne dane
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;
}
I use to scan Qr Code Google Vison but I have a little problem. When scan QR Code It automatically saves me several objects the same. How do if you scan QR Code read one data.
For example:
my class Employee
model object Employee
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
metoda która skanuje OR Kod
private ArrayList<Employee> employeeList = new ArrayList<Employee>();
...
//this method with read vale with QR Code
@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);
}