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))
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)
}