title: Xamarin.Android Camera Permissions with ZXing.Net.Mobile only works after app restart
body: <p>I am using ZXing.Net.Mobile in a Xamarin.Forms project. It works fine on iOS, but on Android, the first time I use the scanner, I get the camera permissions popup, and grant them.</p>
  <p>There is no image from the camera immediately after the permissions. If I quit the app and re-launch, the camera works fine from that point forward. How can I get it to work right away? Even if I close my view, dispose and re-initialize it, it still doesn't work until the app restarts.</p>
  <p>Here is relevant code:</p>
  <pre><code>public partial class CEUScanModalPage : ContentPage, INotifyPropertyChanged {
      private bool _isScanning;
  
      public CEUScanModalPage() {
          InitializeComponent();
          IsScanning = false;
          BindingContext = this;
          Indicator.Start();
      }
  
      public bool IsScanning {
          get {
              return _isScanning;
          }
          set {
              _isScanning = value;
              OnPropertyChanged();
          }
      }
  
      private async void OnCloseButtonClicked(object sender, EventArgs args) {
          await Navigation.PopModalAsync();
      }
  
      protected override void OnAppearing() {
          base.OnAppearing();
          IsScanning = true;
      }
  
      protected override void OnDisappearing() {
          base.OnDisappearing();
          _scanView.OnScanResult -= Handle_OnScanResult;
          _scanView.IsAnalyzing = false;
          _scanView.IsScanning = false;
          ParentGrid.Children.Remove(_scanView);
          _scanView = null;
      }
  
      public async void Handle_OnScanResult(Result result) {
          IsScanning = false;
  
        
      }
  }
  </code></pre>
  <p>XAML:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
  &lt;ContentPage xmlns=&quot;http://xamarin.com/schemas/2014/forms&quot; xmlns:x=&quot;http://schemas.microsoft.com/winfx/2009/xaml&quot; xmlns:local=&quot;clr-namespace:BehaviorLive&quot; xmlns:grial=&quot;clr-namespace:UXDivers.Grial;assembly=UXDivers.Grial&quot; xmlns:ffimageloading=&quot;clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms&quot; xmlns:fftransformations=&quot;clr-namespace:FFImageLoading.Transformations;assembly=FFImageLoading.Transformations&quot; xmlns:zxing=&quot;clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms&quot;
  
      x:Class=&quot;BehaviorLive.Views.CEUScanModalPage&quot;
                  NavigationPage.HasNavigationBar=&quot;False&quot;
      Style=&quot;{ StaticResource MainMenuOrModalBackgroundStyle }&quot;&gt;
      &lt;ContentPage.Resources&gt;
          &lt;ResourceDictionary
              Source=&quot;/Styles/TabControl/SimpleTabResources.xaml&quot; /&gt;
      &lt;/ContentPage.Resources&gt;
  
      &lt;ContentPage.Content&gt;
          &lt;Grid&gt;
              &lt;Grid.RowDefinitions&gt;
                  &lt;RowDefinition
                      Height=&quot;145&quot; /&gt;
                  &lt;RowDefinition
                      Height=&quot;*&quot; /&gt;
              &lt;/Grid.RowDefinitions&gt;
  
              &lt;Grid
                  RowSpacing=&quot;0&quot;
                  ColumnSpacing=&quot;0&quot;
                  Margin=&quot;0,0,0,10&quot;
                  VerticalOptions=&quot;EndAndExpand&quot;&gt;
                  &lt;Grid.RowDefinitions&gt;
                      &lt;RowDefinition
                          Height=&quot;10&quot; /&gt;
                      &lt;RowDefinition
                          Height=&quot;Auto&quot; /&gt;
                      &lt;RowDefinition
                          Height=&quot;Auto&quot; /&gt;
                  &lt;/Grid.RowDefinitions&gt;
  
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition
                          Width=&quot;120&quot; /&gt;
                      &lt;ColumnDefinition
                          Width=&quot;*&quot; /&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
  
                  &lt;!-- LOGO --&gt;
                  &lt;Label
                      Grid.Row=&quot;0&quot;
                      Grid.RowSpan=&quot;3&quot;
                      Margin=&quot;20,0&quot;
                      TextColor=&quot;{ DynamicResource InverseTextColor }&quot;
                      FontSize=&quot;74&quot;
                       FontFamily=&quot;{StaticResource FontAwesomeSolid}&quot;
                      Text=&quot;{ x:Static local:FontawesomeSolidFont.Qrcode }&quot;
                      Style=&quot;{ StaticResource FontIcon }&quot;
                      HorizontalOptions=&quot;Start&quot;
                      VerticalTextAlignment=&quot;Center&quot; /&gt;
  
                  &lt;!-- WELCOME --&gt;
                  &lt;Label
                      Grid.Row=&quot;1&quot;
                      Grid.Column=&quot;1&quot;
                      Text=&quot;CEU Checkin&quot;
                      FontSize=&quot;22&quot;
                      TextColor=&quot;{ DynamicResource InverseTextColor }&quot;
                      Style=&quot;{ StaticResource LabelBoldStyle }&quot;
                      VerticalOptions=&quot;End&quot;
                      HorizontalOptions=&quot;Start&quot; /&gt;
  
                  &lt;!-- SUB --&gt;
                  &lt;Label
                      Grid.Row=&quot;2&quot;
                      Grid.Column=&quot;1&quot;
                      Text=&quot;Scan QR Code to check in/out of your event&quot;
                      FontSize=&quot;16&quot;
                      TextColor=&quot;{ DynamicResource InverseTextColor }&quot;
                      VerticalOptions=&quot;Start&quot;
                      HorizontalOptions=&quot;Start&quot; /&gt;
              &lt;/Grid&gt;
  
              &lt;Grid
                  Grid.Row=&quot;1&quot;
                  BackgroundColor=&quot;{ DynamicResource MainWrapperBackgroundColor }&quot;
                  grial:Effects.ApplyIOSSafeAreaAsPadding=&quot;Bottom&quot; x:Name=&quot;ParentGrid&quot;&gt;
                  &lt;!-- TAB --&gt;
  
                  &lt;StackLayout x:Name=&quot;LoadingIndicator&quot; Grid.Row=&quot;0&quot; VerticalOptions=&quot;CenterAndExpand&quot;&gt;
                      &lt;local:CustomActivityIndicator
                          Grid.Row=&quot;0&quot;
  
                          x:Name=&quot;Indicator&quot;
                          HorizontalOptions=&quot;Center&quot;
                          VerticalOptions=&quot;Start&quot; /&gt;
  
                      &lt;Label
                          Grid.Row=&quot;1&quot;
                          FontSize=&quot;Large&quot;
                          HorizontalTextAlignment=&quot;Center&quot;
                          Text=&quot;{ grial:Translate StringLoading }&quot; /&gt;
                  &lt;/StackLayout&gt;
  
                  &lt;zxing:ZXingScannerView Grid.Row=&quot;0&quot; Grid.RowSpan=&quot;2&quot; x:Name=&quot;_scanView&quot; OnScanResult=&quot;Handle_OnScanResult&quot; IsScanning=&quot;{Binding IsScanning}&quot;
                                  WidthRequest=&quot;200&quot; HeightRequest=&quot;200&quot; /&gt;
  
  
  
  
              &lt;/Grid&gt;
  
              &lt;!-- CLOSE ICON --&gt;
              &lt;Label
                  Style=&quot;{StaticResource IconCloseLabelStyle}&quot;&gt;
                  &lt;Label.GestureRecognizers&gt;
                      &lt;TapGestureRecognizer
                          Tapped=&quot;OnCloseButtonClicked&quot; /&gt;
                  &lt;/Label.GestureRecognizers&gt;
              &lt;/Label&gt;
  
          &lt;/Grid&gt;
      &lt;/ContentPage.Content&gt;
  &lt;/ContentPage&gt;
  </code></pre>
  <p>MainActivity.cs</p>
  <pre><code>  public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) {
          Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
  
          base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
      }
  </code></pre>