barcodeCapture打开摄像头和预览摄像头,但无法在三星设备(J7 pro)上进行检索,但可以在华为或三星j7上工作!
API:MobileVisionBarcodeScanner API
代码:
barcodeCapture.setShowDrawRect(true);
barcodeCapture.setAllowEnterTransitionOverlap(true);
barcodeCapture.setShowDrawRect(true);
barcodeCapture.setSupportMultipleScan(false);
barcodeCapture.setTouchAsCallback(false);
barcodeCapture.shouldAutoFocus(true);
barcodeCapture.setBarcodeFormat(Barcode.ALL_FORMATS);
barcodeCapture.setCameraFacing(CameraSource.CAMERA_FACING_BACK);
barcodeCapture.setRetrieval(new BarcodeRetriever() {
@Override
public void onRetrieved(Barcode barcode) {
_barcode_value = barcode.displayValue;
_func_send_barcode();
}
@Override
public void onRetrievedMultiple(Barcode closetToClick, List<BarcodeGraphic> barcode) {
_barcode_value = barcode.get(0).getBarcode().displayValue;
_func_send_barcode();
}
@Override
public void onBitmapScanned(SparseArray<Barcode> sparseArray) {
}
@Override
public void onRetrievedFailed(String reason) {
}
@Override
public void onPermissionRequestDenied() {
}
});
barcodeCapture.refresh();
XML:
<fragment android:id="@+id/barcode" android:name="com.google.android.gms.samples.vision.barcodereader.BarcodeCapture" android:layout_width="fill_parent" android:layout_height="fill_parent" app:gvb_auto_focus="true" app:gvb_code_format="all_format" app:gvb_draw="true" app:gvb_multiple="false" app:gvb_touch="false" app:gvb_rect_colors="@array/rect_color" />