我尝试实现Zxing条形码扫描器库,这是我第一次对其进行完美扫描,并且捕获了条形码。尝试扫描另一个条形码时,以前捕获的条形码图像保持不变。
还可以在扫描仪本身中设置关闭按钮,或者只共享最佳的扫描仪库
代码如下:
package com.erplogic.handledscanner;
import me.dm7.barcodescanner.zxing.ZXingScannerView;
import static android.Manifest.permission.CAMERA;
public class ScannedDetails extends AppCompatActivity implements
AsynchronousResponse , ZXingScannerView.ResultHandler{
String lineItemID;
private ZXingScannerView scannerView;
private LinearLayout scanner;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scanned_details);
scanner= findViewById(R.id.scan_recycle);
// Scanner button
ImageButton scannerButton = findViewById(R.id.scanner_button);
scannerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
recyclerView.setVisibility(View.GONE);
scannerView = new ZXingScannerView(ScannedDetails.this);
scanner.addView(scannerView);
}
}
});
}
@Override
public void handleResult(Result result) {
Toast.makeText(ScannedDetails.this, result.getText(),
Toast.LENGTH_LONG).show();
}
@Override
public void onPointerCaptureChanged(boolean hasCapture) {
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public void onResume() {
super.onResume();
if (scannerView == null) {
scannerView = new ZXingScannerView(ScannedDetails.this);
scanner.addView(scannerView);
}
scannerView.setResultHandler(this);
scannerView.startCamera();
}
}
}