我的条目看起来像这样:
在输入数据之前,必须使用条码扫描仪填写条码。当 Firestore 中存在条形码时,我希望增加产品数量。当条形码在Firestore中不可用时,Intent到另一个类。
代码 :
@Override
public void handleResult(Result result) {
final String scanResult = result.getText();
ToneGenerator toneNotification = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
toneNotification.startTone(ToneGenerator.TONE_PROP_BEEP, 150);
collectionReference.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot queryDocumentSnapshot : task.getResult()) {
// if barcode is existing, then product quantity to increment
if (queryDocumentSnapshot.getString("barCode") != null) {
collectionReference.document(queryDocumentSnapshot.getId()).update("productQuantity", FieldValue.increment(1));
Intent moveView = new Intent(ScannersActivity.this, ViewData.class);
moveView.putExtra("documentID", documentID);
startActivity(moveView);
finish();
} else { // If barcode is not available in firestore, then intent to another class
Intent moveCode = new Intent(ScannersActivity.this, AddItems.class);
moveCode.putExtra("sendDocumentID", documentID);
moveCode.putExtra("ScanResult", scanResult);
startActivity(moveCode);
finish();
}
}
}
}
});
}
大话西游666
ITMISS
相关分类