Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 61c14b6

Browse files
[Android] MLKit camera resume when app resumes from background. #893
1 parent 3858c44 commit 61c14b6

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/mlkit/mlkit-cameraview.android.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class SizePair {
1717
};
1818
}
1919

20-
// TODO pause/resume handling
2120
export abstract class MLKitCameraView extends MLKitCameraViewBase {
2221
private surfaceView: any; // android.view.SurfaceView;
2322
private bytesToByteBuffer = new Map();
@@ -91,10 +90,8 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
9190
}
9291

9392
initNativeView(): void {
94-
application.on("resume", arg => {
95-
this.runCamera();
96-
} );
9793
super.initNativeView();
94+
application.on("resume", arg => this.runCamera());
9895
}
9996

10097
private hasCamera() {
@@ -112,11 +109,11 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
112109
this.surfaceView = new android.view.SurfaceView(utils.ad.getApplicationContext());
113110
nativeView.addView(this.surfaceView);
114111

115-
// Note that surfaceview callbacks didn't seem to work, so using a good old timeout (https://github.com/firebase/quickstart-android/blob/0f4c86877fc5f771cac95797dffa8bd026dd9dc7/mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/CameraSourcePreview.java#L47)
116112
this.runCamera();
117113
}
118114

119115
private runCamera(): void {
116+
// Note that surfaceview callbacks didn't seem to work, so using a good old timeout (https://github.com/firebase/quickstart-android/blob/0f4c86877fc5f771cac95797dffa8bd026dd9dc7/mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/CameraSourcePreview.java#L47)
120117
setTimeout(() => {
121118
const surfaceHolder = this.surfaceView.getHolder();
122119
const cameraFacingRequested = android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK;
@@ -224,7 +221,7 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
224221
this.camera.setPreviewDisplay(surfaceHolder);
225222
this.camera.startPreview();
226223

227-
}, 500); // TODO 500 works fine on my device, but would be wise to explore the boundaries
224+
}, 500);
228225
}
229226

230227
protected updateTorch(): void {

0 commit comments

Comments
 (0)