From f598d0d6b8aff8026fc9cb2c207956fb08f4207a Mon Sep 17 00:00:00 2001 From: orfelorfel23 Date: Wed, 10 Jun 2026 20:33:11 +0200 Subject: [PATCH] fix: Bypass ausbc capture to fix permission error and black screen --- .../expo/modules/usbcamera/UsbCameraView.kt | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/modules/usb-camera/android/src/main/java/expo/modules/usbcamera/UsbCameraView.kt b/modules/usb-camera/android/src/main/java/expo/modules/usbcamera/UsbCameraView.kt index bba67a22..fedc28db 100644 --- a/modules/usb-camera/android/src/main/java/expo/modules/usbcamera/UsbCameraView.kt +++ b/modules/usb-camera/android/src/main/java/expo/modules/usbcamera/UsbCameraView.kt @@ -21,8 +21,7 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context addView(textureView, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)) val cameraRequest = CameraRequest.Builder() - .setPreviewWidth(1280) - .setPreviewHeight(720) + .setFrontCamera(false) .create() val activityContext = appContext.currentActivity ?: context @@ -79,7 +78,7 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context cameraClient = CameraClient.newBuilder(activityContext) .setCameraStrategy(CameraUvcStrategy(activityContext)) .setCameraRequest(cameraRequest) - .setEnableGLES(true) + .setEnableGLES(false) .build() post { @@ -103,23 +102,17 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context } try { - client.captureImage(object : ICaptureCallBack { - override fun onBegin() { - // Do nothing + // Bypass ausbc's captureImage and permission checks by grabbing the texture view bitmap directly! + val bitmap = textureView.bitmap + if (bitmap != null) { + val file = java.io.File(java.net.URI(savePath).path.takeIf { it.isNotEmpty() } ?: savePath.replace("file://", "")) + java.io.FileOutputStream(file).use { out -> + bitmap.compress(android.graphics.Bitmap.CompressFormat.JPEG, 95, out) } - - override fun onError(error: String?) { - promise.reject("ERR_CAPTURE_FAILED", error ?: "Unknown error", null) - } - - override fun onComplete(path: String?) { - if (path != null) { - promise.resolve(path) - } else { - promise.reject("ERR_CAPTURE_FAILED", "File path was null", null) - } - } - }, savePath) + promise.resolve(savePath) + } else { + promise.reject("ERR_CAPTURE_FAILED", "TextureView bitmap is null (is preview running?)", null) + } } catch (e: Exception) { promise.reject("ERR_CAPTURE_EXCEPTION", e.message ?: "Capture threw an exception", e) }