title: Launching a QR scanner from Android web view and returning the scanned result using Xamarin
body: <p>I have this Xamarin application that launches a QR scanner when a button is clicked. This button click is handled in Javascript. When the button is clicked, below C# code gets called. This supposed to launch the QR scanner and once the value is scanned, the scanned value is returned to a Javascript function. But as soon as the button to scan QR code is clicked, web view app gets to the background but camera is not launched to scan the QR code.</p>
  
  <pre><code> public class QRScannerJSInterface : Java.Lang.Object
      {
          QRScanner qrScanner;
          WebView webView;
  
          public QRScannerJSInterface(WebView webView)
          {
              this.webView = webView;
              qrScanner = new QRScanner();
          }
  
          [Export]
          [JavascriptInterface]
          public void ScanQR()
          {
              String result = qrScanner.ScanQR();
              var js = string.Format("getQRValue('{0}');", result);
              webView.LoadUrl("javascript:" + js);
              //call the Javascript method here with "result" as its parameter to get the scanned value
          }
  </code></pre>
  
  <p>Below is how the main activity calls this class.</p>
  
  <pre><code>        webView = FindViewById&lt;WebView&gt;(Resource.Id.webView);
          webView.Settings.JavaScriptEnabled = true;
          webView.Settings.AllowFileAccessFromFileURLs = true;
          webView.Settings.AllowUniversalAccessFromFileURLs = true;
          webView.Settings.AllowFileAccess = true;
          webView.AddJavascriptInterface(new QRScannerJSInterface(webView),"CSharpQRInterface");
  </code></pre>
  
  <p>Below is the QRScanner code.</p>
  
  <pre><code>class QRScanner
      {
          MobileBarcodeScanner scanner;
  
          public QRScanner()
          {
              scanner = new MobileBarcodeScanner();
          }
  
          public String ScanQR()
          {
              scanner.UseCustomOverlay = false;
              scanner.TopText = "Scanning for barcode";
              Task&lt;ZXing.Result&gt; result = scanner.Scan();
              return result.ToString();
          }
      }
  </code></pre>
  
  <p>What am I doing wrong here? Any help would be much appreciated.</p>