fix: Bypass ausbc capture to fix permission error and black screen

This commit is contained in:
2026-06-10 20:33:11 +02:00
parent 4e4608cbea
commit f598d0d6b8
@@ -21,8 +21,7 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context
addView(textureView, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)) addView(textureView, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
val cameraRequest = CameraRequest.Builder() val cameraRequest = CameraRequest.Builder()
.setPreviewWidth(1280) .setFrontCamera(false)
.setPreviewHeight(720)
.create() .create()
val activityContext = appContext.currentActivity ?: context val activityContext = appContext.currentActivity ?: context
@@ -79,7 +78,7 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context
cameraClient = CameraClient.newBuilder(activityContext) cameraClient = CameraClient.newBuilder(activityContext)
.setCameraStrategy(CameraUvcStrategy(activityContext)) .setCameraStrategy(CameraUvcStrategy(activityContext))
.setCameraRequest(cameraRequest) .setCameraRequest(cameraRequest)
.setEnableGLES(true) .setEnableGLES(false)
.build() .build()
post { post {
@@ -103,23 +102,17 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context
} }
try { try {
client.captureImage(object : ICaptureCallBack { // Bypass ausbc's captureImage and permission checks by grabbing the texture view bitmap directly!
override fun onBegin() { val bitmap = textureView.bitmap
// Do nothing 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)
} }
promise.resolve(savePath)
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 { } else {
promise.reject("ERR_CAPTURE_FAILED", "File path was null", null) promise.reject("ERR_CAPTURE_FAILED", "TextureView bitmap is null (is preview running?)", null)
} }
}
}, savePath)
} catch (e: Exception) { } catch (e: Exception) {
promise.reject("ERR_CAPTURE_EXCEPTION", e.message ?: "Capture threw an exception", e) promise.reject("ERR_CAPTURE_EXCEPTION", e.message ?: "Capture threw an exception", e)
} }