-
Notifications
You must be signed in to change notification settings - Fork 457
[Bug] CameraView - "Couldn't find any suitable preview size" - "Access denied finding property "persist.vendor.camera.privapp.list" #1509
Description
Description
On some Android devices (at least Xiaomi Redmi 7/8), trying to show back camera output, results in error:
Couldn't find any suitable preview size
and then:
Access denied finding property "persist.vendor.camera.privapp.list"
Steps to Reproduce
- Include latest XCT nuget package in project.
- Add CameraView on sample page with CameraOptions = Back.
- Run on Xiaomi Redmi 7/8.
Expected Behavior
Rear camera output is visible on CameraView component
Actual Behavior
Nothing shows
Basic Information
- Version with issue: 1.2.0
- IDE: Visual Studio for MacOS
- Platform Target Frameworks:
- Android: 29
- Affected Devices: Xiaomi Redmi 7/8
Workaround
I've downloaded XCT source project and then included it into my solution. This way I was able to debug this issue and to fix the broken code. The problem is in CameraFragment.ChooseOptimalSize()
method - precisely in this conditional statement:
if (option.Width <= maxWidth && option.Height <= maxHeight && option.Height == option.Width * h / w)
(see here)
Variables "h" and "w" are:
var w = aspectRatio.Width;
var h = aspectRatio.Height;
When using Xiaomi Redmi, the aspectRatio of back camera is: 3016 (h) X 4032 (w). It turns out, that it is NOT precisely an "3/4" aspect ratio (0.748... instead of 0.75). This way, the above shown conditional statement was never true (i.e. the second part of this statement) and "optimal size" was never found. This resulted in mentioned errors.
I've fixed it this way:
var w = aspectRatio.Width;
var h = aspectRatio.Height;
double cameraAspectRatio = Math.Round(h / (double)w, 2);
foreach (var option in choices)
{
double optionAspectRatio = Math.Round(option.Height / (double)option.Width, 2);
if (option.Width <= maxWidth && option.Height <= maxHeight &&
optionAspectRatio == cameraAspectRatio)
{
if (option.Width >= width && option.Height >= height)
{
bigEnough.Add(option);
}
else
{
notBigEnough.Add(option);
}
}
}
In general, I calculate both ratios (current option's ratio and back camera ratio), round them to two decimals and then compare. It works now (at least for Xiaomi issue, because 0.748 ~= 0.75).