Search code examples
androidxamarinqr-codezxingxamarin.forms

Xamarin Forms QR code scanner blank screen


I have a Xamarin Forms 2.0 application that uses ZXing.Net.Mobile and ZXing.Net.Mobile.Forms version 2.0.3.1. I'm trying to build a simple QR code scanner, but whenever I launch the ZXingScannerPage on Android I can see the default overlay (with the text and the red line) but I don't see the output of the camera so I can't actually scan anything. I have already listed the Camera permission in my AndroidManifest:

<uses-permission android:name="android.permission.CAMERA" />

I tried the sample code from the readme: https://github.com/Redth/ZXing.Net.Mobile as well as from their Samples/Forms project. I now have this code:

private async void OnScanQrClicked(object sender, EventArgs e)
{
    _scannerPage = new ZXingScannerPage();
    _scannerPage.OnScanResult += HandleScanResult;

    await Navigation.PushAsync(_scannerPage);
}

private void HandleScanResult(Result result)
{
    _scannerPage.IsScanning = false;

    Device.BeginInvokeOnMainThread(() =>
    {
        Navigation.PopAsync();
        DisplayAlert("Scanned code", result.Text, "OK");
    });
}

Some more specs: I'm running Android 5.1 on a Moto G (v1).

Why am I not seeing the output of the camera?


Solution

  • I fixed it by getting rid of ZXing.Net.Mobile.Forms and downgrading ZXing.Net.Mobile from 2.0 to 1.5. I had to change my implementation, but that was relatively easy.

    Another thing people may look at in the future (I didn't try it) is adding the flashlight permission: https://github.com/Redth/ZXing.Net.Mobile/issues/227.