Xamarin.Android camera preview dull on a particular device

141 views Asked by At

We have an app which uses the Manatee Works barcode scanner. This scanner is really good except...

On a particular device - a CAT S41, the scanner preview is dull.

On other devices, and with other apps running on the same device, it is fine.

I have narrowed it down to the camera preview, by implementing the Camera Preview as demonstrated here:

https://github.com/xamarin/xamarin-forms-samples/tree/master/CustomRenderers/View/Droid

This exhibits the same behaviour which is:

  1. When the preview is first displayed, the app screen dims, the preview window appears, and the app screen restores back to its original brightness. However, the preview is dim.
  2. If the preview is subsequently displayed, the screen does not dim, but the preview is dim.

We have a demo app from Manatee which does not exhibit this behaviour.

The device is running Android 7.0. Other devices running Android 7.0 don't exhibit the behaviour.

Versions: Xamarin.Forms 2.5.0.1222203 Xamarin.Android.Support.* version 25.4.0.2

The above are the same as the demo app.

Any thoughts?

1

There are 1 answers

0
James Lavery On

Found the solution.

We had a style applied to our MainActivity with the following attribute:

<item name="android:backgroundDimEnabled">true</item>

This usually causes/allows application screen to dim when an alert is displayed. However, it also has the side effect of making the SurfaceView used by the scanner dim also. Similar to this bug/behaviour reported here:

https://github.com/google/ExoPlayer/issues/3733

The solution is to set this to false.

One side effect is that the main app window doesn't dim when an alert is displayed. However, this is the default Android behaviour anyway (i.e. backgroundDimEnabled is false by default).