Search code examples
c#xamarin.androidzxing

How can I get the content of QR code scanned in an another activity?


well I use Zxing to scan a QR Code. That is my code for that:

  public class ScanActivity : Activity  
    {
        public ZXing.Result scanningResult;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.activity_scan);
            mReturnValue = new Intent();
            Button scanBtn = FindViewById<Button>(Resource.Id.button_scan);

            MobileBarcodeScanner.Initialize(Application);
            scanBtn.Click += async (sender, e) =>
            {
                var scanner = new ZXing.Mobile.MobileBarcodeScanner();
                scanningResult = await scanner.Scan();

          //       if (scanningResult != null)
          //          Console.WriteLine("Scanned Barcode: " + scanningResult.Text);
            };

My problem is that I couldn't find how can I get and use the values of the scanned result in another activity?


Solution

  • From the activity, where you need the result you should start the scan activity for result. In the calling activity OnActivityResult event you can do what you want with the retuned code.

    Look at the sample:

    https://developer.xamarin.com/recipes/android/fundamentals/activity/start_activity_for_result/