code-scanner
code-scanner copied to clipboard
Black screen on onePlus nord CE
The black screen is appearing whenever the scanner is opened, This is happening only for OnePlus Nord CE 5G Device (might be other devices too). I checked it for OnePlus 6, 6t, 9R, and 10R but it is working fine for these devices too. Even on the demo app, I'm facing the same issue.
Library version:
implementation 'com.github.yuriy-budiyev:code-scanner:2.3.2'
Implementation:
decodeCallback = DecodeCallback {
runOnUiThread {
if (Utills.isInternetConnected(context)) {
if (it.text.toUpperCase(Locale.ENGLISH).endsWith(Constants.PDF_FORMAT)) {
openPdf(it.text)
} else loadWebView(it.text)
} else {
showNoInternetDialog(getString(R.string.no_internet_message))
}
}
}
errorCallback = ErrorCallback { // or ErrorCallback.SUPPRESS
runOnUiThread {
showLongMessage("${getString(R.string.error)} : ${it.message}")
}
}
<com.budiyev.android.codescanner.CodeScannerView
android:id="@+id/scanner_view"
android:layout_width="match_parent"
android:layout_height="0dp"
app:autoFocusButtonColor="@color/color_orange_background"
app:autoFocusButtonVisible="true"
app:flashButtonColor="@color/color_orange_background"
app:flashButtonVisible="true"
app:frameAspectRatioHeight="1"
app:frameAspectRatioWidth="1"
app:frameColor="@color/color_orange_background"
app:frameCornersRadius="@dimen/margin_32_dp"
app:frameCornersSize="@dimen/dimen_eighty"
app:frameSize="0.75"
app:frameThickness="@dimen/eight_dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar"
app:maskColor="#77000000" />
Device Details: Name: OnePlus Nord CE 5G Android Version: 12
So after verifying the issue on the OP NORD 5G, I noticed a few things.
when the size is returned from the Utils.findSuitableImageSize()
set in parameters.setPreviewSize(imageWidth, imageHeight)
causing the issue and throwing the exception (which is ignored) inside a startPreviewInternal()
method.
it is throwing below-mentioned exception:
java.lang.RuntimeException: setParameters failed
parameters.getSupportedPreviewSizes() returns below supported sizes.
h: 2080 w: 4624
h: 2080 w: 4608
h: 1890 w: 4160
h: 1872 w: 4160
h: 2250 w: 4000
h: 1818 w: 4000
h: 1800 w: 4000
h: 2160 w: 3840
h: 1644 w: 3840
h: 2592 w: 3456
h: 2464 w: 3280
h: 2448 w: 3264
h: 1836 w: 3264
h: 1472 w: 3264
h: 2400 w: 3200
h: 1440 w: 3168
h: 2160 w: 2880
h: 1944 w: 2592
h: 1512 w: 2688
h: 1080 w: 2400
h: 1748 w: 2328
h: 1168 w: 2592
h: 1080 w: 2376
h: 1728 w: 2304
h: 1080 w: 2160
h: 1080 w: 1920
h: 864 w: 1920
h: 822 w: 1920
h: 1200 w: 1600
h: 800 w: 1600
h: 720 w: 1600
h: 720 w: 1584
h: 1080 w: 1440
h: 960 w: 1280
h: 768 w: 1280
h: 768 w: 1024
h: 720 w: 1280
h: 540 w: 1188
h: 540 w: 1200
h: 360 w: 840
h: 400 w: 800
h: 360 w: 792
h: 540 w: 720
h: 480 w: 720
h: 480 w: 640
h: 360 w: 640
h: 288 w: 352
h: 240 w: 320
h: 144 w: 176
h: 2250 w: 4000
and findSuitableImageSize()
is returning h: 2250 w: 4000, but for this specific size I'm not able to see the preview, and an exception is being thrown. but if I use this size (h: 2080 w: 4624), it is working fine for me. I don't know the exact reason but I've commented few lines of code and it is working fine on all of the devices I checked.
change
@NonNull
public static Point findSuitableImageSize(@NonNull final Parameters parameters,
final int frameWidth, final int frameHeight) {
final List<Camera.Size> sizes = parameters.getSupportedPreviewSizes();
for(int i = 0; i < sizes.size(); i++) {
Log.d("====size: ", "h: "+ sizes.get(i).height + " w: "+sizes.get(i).width);
}
if (sizes != null && !sizes.isEmpty()) {
Collections.sort(sizes, new CameraSizeComparator());
// final float frameRatio = (float) frameWidth / (float) frameHeight;
for (float distortion = MIN_DISTORTION; distortion <= MAX_DISTORTION;
distortion += DISTORTION_STEP) {
for (final Camera.Size size : sizes) {
final int width = size.width;
final int height = size.height;
// if (width * height >= MIN_PREVIEW_PIXELS &&
// Math.abs(frameRatio - (float) width / (float) height) <= distortion) {
Log.d("====returned size", "h: "+height+" w: "+width);
return new Point(width, height);
// }
}
}
}
final Camera.Size defaultSize = parameters.getPreviewSize();
if (defaultSize == null) {
throw new CodeScannerException("Unable to configure camera preview size");
}
Log.d("====default size", "h: "+defaultSize.height+" w: "+defaultSize.width);
return new Point(defaultSize.width, defaultSize.height);
}
Note: Not all OP NORD 5G devices are facing this issue. some OP 5 devices are also facing the same problem.
I am also facing the same issue on my project on the OnePlus Nord CE device. I have used the library using Gradle (v2.3.2).
@vishalnaikawadi Is there any way to fix it without modifying the library code?
A co-worker also showed me this issue on his OnePlus Nord CE device