Generate qr code in xamarin.android

Youssef 46 Reputation points
2022-01-17T12:38:50.423+00:00

I have a problem generating qr code. I used a sample from site:
https://www.c-sharpcorner.com/article/generate-barcode-and-qr-code-in-xamarin-android/

But I got a null reference error at this line:
bitmapMatrix = new MultiFormatWriter().encode(message, BarcodeFormat.QR_CODE, size, size);

In my project I have installed the next packages:

  • Zxing.net.
  • Xamarin.AndroidX.AppCompat
  • Xamarin.Essentials
  • Xamarin.Google.Android.Material

Does anyone have a clue why I am getting a null reference?

Gr. Youssef

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
{count} votes

Accepted answer
  1. JarvanZhang 23,936 Reputation points
    2022-01-18T09:29:20.78+00:00

    Hello yaza,​

    Welcome to our Microsoft Q&A platform!

    The ZXing.Net API may not perform well on Android. Try using ZXing.Net.Mobile nuget instead, which is a mobile-specific. I've tested the function code with this package, it works as expected. The nuget requires the Xamarin.AndroidX.Legacy.Support.V4 dependency, please install the package for your project.

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful