Я пытаюсь следовать примеру, показанному на странице zxing в GitHub для непрерывного сканера QRCode. Проблема в том, что когда я запускаю проект на своем устройстве, все, что я получаю, это черный экран вместо предварительного просмотра камеры телефона. Ниже мой код в SelecionarArduinoActivity. java:
public class SelecionarArduinoActivity extends AppCompatActivity {
private SelecionarArduinoController controller;
private DecoratedBarcodeView barcodeView;
private BeepManager beepManager;
private String lastText;
private BarcodeCallback callback = new BarcodeCallback() {
@Override
public void barcodeResult(BarcodeResult result) {
if(result.getText() == null || result.getText().equals(lastText)){
return;
}
lastText = result.getText();
barcodeView.setStatusText(result.getText());
beepManager.playBeepSoundAndVibrate();
ImageView imageView = findViewById(R.id.barcodePreview);
imageView.setImageBitmap(result.getBitmapWithResultPoints(Color.YELLOW));
}
@Override
public void possibleResultPoints(List<ResultPoint> resultPoints) {
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selecionar_arduino);
barcodeView = findViewById(R.id.barcode_scanner);
Collection<BarcodeFormat> formats = Arrays.asList(BarcodeFormat.QR_CODE);
barcodeView.getBarcodeView().setDecoderFactory(new DefaultDecoderFactory(formats));
barcodeView.initializeFromIntent(getIntent());
barcodeView.decodeContinuous(callback);
beepManager = new BeepManager(this);
controller = new SelecionarArduinoController(SelecionarArduinoActivity.this);
}
И для моего макета в xml я получил:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.journeyapps.barcodescanner.DecoratedBarcodeView
android:id="@+id/barcode_scanner"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_above="@+id/buttonsLayout"
android:layout_alignParentTop="true">
</com.journeyapps.barcodescanner.DecoratedBarcodeView>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/buttonsLayout"
android:layout_toLeftOf="@+id/centerHorizont">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pause"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Resume"
/>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:id="@+id/centerHorizont" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/centerHorizont"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/buttonsLayout"
android:id="@+id/barcodePreview" />
</RelativeLayout>
На данный момент, пожалуйста, игнорируйте кнопки пауза и возобновление, я получил это для примера, но я не собираюсь его использовать.
И, наконец, мой результат Logcat:
03/11 18:42:19: Launching 'app' on Xiaomi Mi A3.
$ adb shell am start -n "br.usp.ardhouse/br.usp.ardhouse.activity.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 13138 on device 'xiaomi-mi_a3-d0c96fd050b8'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/Perf: Connecting to perf service.
E/Perf: Fail to get file list br.usp.ardhouse
getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
E/Perf: Fail to get file list br.usp.ardhouse
getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
W/br.usp.ardhous: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/br.usp.ardhous: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
I/AdrenoGLES: QUALCOMM build : 1604d02, I97efb879e3
Build Date : 09/25/19
OpenGL ES Shader Compiler Version: EV031.27.05.02
Local Branch :
Remote Branch :
Remote Branch :
Reconstruct Branch :
Build Config : S P 8.0.11 AArch64
I/AdrenoGLES: PFP: 0x016ee187, ME: 0x00000000
W/AdrenoUtils: <ReadGpuID_from_sysfs:194>: Failed to open /sys/class/kgsl/kgsl-3d0/gpu_model
W/AdrenoUtils: <ReadGpuID:218>: Failed to read chip ID from gpu_model. Fallback to use the GSL path
W/RenderThread: type=1400 audit(0.0:342325): avc: denied { search } for name="kgsl" dev="sysfs" ino=36975 scontext=u:r:untrusted_app:s0:c216,c256,c512,c768 tcontext=u:object_r:sysfs_kgsl:s0 tclass=dir permissive=0
W/Gralloc3: mapper 3.x is not supported
W/System: A resource failed to call close.
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@433ea66