Camera screen turns black while opening camera and go to another activity and came back to camera activity in Redmi Note 8

612 views
Skip to first unread message

Shivani Patel

unread,
Sep 2, 2021, 5:54:33 AM9/2/21
to Android CameraX Discussion Group

I have used Camerax library
implementation "androidx.camera:camera-camera2:1.0.1"
implementation "androidx.camera:camera-lifecycle:1.0.1"
implementation "androidx.camera:camera-view:1.0.0-alpha27"
and i have not used any sample as our requirement is different and i have used activity directly for camera
Steps to reproduce :

  1. User has captured multiple images
  2. when user tap on captured image we are displaying image in full screen
  3. when user came back to camera activity by pressing back button user seeing black preview

This is only reproduce in Redmi Note 8

Scott Nien

unread,
Sep 2, 2021, 11:50:28 AM9/2/21
to Shivani Patel, Android CameraX Discussion Group
Hi Shivani, 
This seems quite serious.   Can you file a public bug to track this ?  
https://issuetracker.google.com/issues/new?component=618491&template=1257717

Some more questions for clarification. 
(1) Is it 100% reproducible on the Redmi Note 8 
(2) Can you reproduce iit with CameraXBasic ?  
(3)  If not,  can you show us some snippet regarding how you use CameraX API 

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/dff57cfc-bb76-44f6-9c64-ae94c4e21f4bn%40android.com.

Wenhung Teng

unread,
Sep 3, 2021, 12:00:37 AM9/3/21
to Android CameraX Discussion Group, Scott Nien, Android CameraX Discussion Group, shivanip...@gmail.com
Hi Shivani, we did a try on Redmi note 8, API 29, QKQ1.200114.002 with CameraXBasic on core lib 1.0.1 and view:1.0.0-alpha27.
We take some photos, and then tap the captured image review at the bottom of the right hand side.
After a few seconds later, we went back to camera activity. 
It seems the preview can be resumed and capture still works.
 
Could you share some sample code / log to us? Perhaps the issue comes from some unstable issue on the hardware/camera framework and/or on a specific device.
Also might only happen on distinct AndroidOS versions of the device. If you still can reproduce the problem, Can you also share the build/version of the device?
Thanks!


Scott Nien 在 2021年9月2日 星期四下午11:50:28 [UTC+8] 的信中寫道:

Shivani Patel

unread,
Sep 6, 2021, 2:49:13 AM9/6/21
to Android CameraX Discussion Group, wenhu...@google.com, Scott Nien, Android CameraX Discussion Group, Shivani Patel
Hello ,

We are using below device. this issue occurs when we capture more images 15-20 images
Redmi Note 8
OS Version : 9

I can share some snippet of my code

- We are calling start camera method from onCreate in Activity as we have used activity for camera
private void startCamera() {
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture =
ProcessCameraProvider.getInstance(this);
cameraProviderFuture.addListener(new Runnable() {
@Override
public void run() {
try {
cameraProvider = cameraProviderFuture.get();
bindPreview(cameraProvider);
} catch (Exception exception) {
BugfenderUtils.e(TAG, exception);
}
}
}, ContextCompat.getMainExecutor(this));
}


private Executor executor = Executors.newSingleThreadExecutor();

public void bindPreview(@NonNull ProcessCameraProvider cameraProvider) {

float ratio = mPreviewWidth / mPreviewHeight;
int rationForCalculation = mCameraViewModel.aspectRatio(mPreviewWidth, mPreviewHeight);

float height;
if (rationForCalculation == 0) {
height = 4 * mPreviewWidth / 3;
} else {
height = 16 * mPreviewWidth / 9;
}

mBinding.texture.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
(int) height));

// Unbind use cases before rebinding
cameraProvider.unbindAll();
Preview preview = new Preview.Builder()
.setTargetAspectRatio((int) ratio)
.build();

CameraSelector cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA;

ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
.build();

ImageCapture.Builder builder = new ImageCapture.Builder();

final ImageCapture mImageCapture = builder
.setTargetRotation(this.getWindowManager().getDefaultDisplay().getRotation())
.setTargetAspectRatio((int) ratio)
.build();
preview.setSurfaceProvider(mBinding.texture.getSurfaceProvider());

androidx.camera.core.Camera camera = cameraProvider.bindToLifecycle(this
, cameraSelector,
preview, imageAnalysis, mImageCapture);

mBinding.capture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(TAG, "mStreamState: " + (mStreamState != null ? mStreamState : "null"));
if (mStreamState != null && mStreamState != PreviewView.StreamState.STREAMING) {
return;
}

try {
double availableSpace =
getAvailableSpace(getExternalFilesDir(null).getParent(),
Constant.StorageType.MB);
if (availableSpace < Constant.MIN_STORAGE_REQUIRED_MB) {
showToast("No enough space");
return;
}
} catch (Exception e) {
e.printStackTrace();
}

setEnableCaptureButton(false);
if (mImageCaptureCount < mMaxImageCount) {
try {
mFile = ImageSaverForCameraX.createImageFile(CameraXActivity.this);

ImageCapture.OutputFileOptions outputFileOptions =
new ImageCapture.OutputFileOptions.Builder(mFile).build();
mImageCapture.takePicture(outputFileOptions, executor,
new ImageCapture.OnImageSavedCallback() {
@Override
public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
CameraXActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
handleCapturedImage();
}
});
}

@Override
public void onError(@NonNull ImageCaptureException error) {
error.printStackTrace();
}
});
} catch (Exception ex) {
ex.printStackTrace();
setEnableCaptureButton(true);
}
} else {
setEnableCaptureButton(true);
}
}
});
}

Shivani Patel

unread,
Oct 12, 2021, 8:54:30 AM10/12/21
to Android CameraX Discussion Group, Shivani Patel, wenhu...@google.com, Scott Nien, Android CameraX Discussion Group
Hello All,

Could you please check this 

Scott Nien

unread,
Oct 12, 2021, 11:25:20 AM10/12/21
to Shivani Patel, Android CameraX Discussion Group, wenhu...@google.com
Hi Shivani, 
To clarify whether it is a Redmi 8 issue or app's issue,  can you help test if it can be reproduced using CameraXBasic ?  


Scott Nien

unread,
Oct 28, 2021, 12:37:29 AM10/28/21
to Shivani Patel, Android CameraX Discussion Group, wenhu...@google.com
Hi Shivani, 
I notice one issue in your code snippet. 

float ratio = mPreviewWidth / mPreviewHeight;
.setTargetAspectRatio((int) ratio).  --->. The ratio can only be either AspectRatio.RATIO_4_3 or AspectRatio.RATIO_16_9 

Not sure if this relates to the issue,  but please try if it can fix the issue. 


Reply all
Reply to author
Forward
0 new messages