2017-12-21 23 views
-1

私のxamarinクロスプラットフォームアプリケーションには、アプリケーションを起動するとすぐに.QRスキャナがコードを読み取るように設定されています。ビープ音を鳴らすと音が鳴り、次回のスキャンの準備が整う。私がやったことは、ボタンをクリックしてスキャナのスタート、そのコードを読むことです、そして、私はもう一度ボタンを押す必要があります。アプリケーションの起動時にバーコードスキャナを初期化する方法

public HomePage() 
     { 
      Button scanBtn = new Button 
      { 
       Text = "Scan Barcode", 
       HorizontalOptions = LayoutOptions.FillAndExpand, 
      }; 

      scanBtn.Clicked += async (sender, args) => 
      { 
       var scanResult = await Acr.BarCodes.BarCodes.Instance.Read(); 
       if (!scanResult.Success) 
       { 
        await this.DisplayAlert("Alert ! ", "Sorry ! \n Failed to read the Barcode !", "OK"); 
       } 
       else 
       { 
        var endpoint = new EndpointAddress("http://192.168.15.33/SMS/WebServices/SMSService.svc"); 
        var binding = new BasicHttpBinding 
        { 
         Name = "basicHttpBinding", 
         MaxBufferSize = 2147483647, 
         MaxReceivedMessageSize = 2147483647 
        }; 

        TimeSpan timeout = new TimeSpan(0, 0, 30); 
        binding.SendTimeout = timeout; 
        binding.OpenTimeout = timeout; 
        binding.ReceiveTimeout = timeout; 

        _client = new SMSServiceClient(binding, endpoint); 
        _client.ValidateStudentAsync("123-admin"); 
        _client.ValidateStudentCompleted += _client_ValidateStudentCompleted; ; 
        // await this.DisplayAlert("Scan Successful !", String.Format("Barcode Format : {0} \n Barcode Value : {1}", scanResult.Format, scanResult.Code), "OK"); 
       } 
      }; 

      Content = new StackLayout 
      { 
       Children = { 
        scanBtn 
       } 
      }; 
     } 

とapp.cs

public class App : Application 
    { 
     public App() 
     { 
      // The root page of your application 
      MainPage = new HomePage(); 
     } 

     protected override void OnStart() 
     { 
      MainPage = new HomePage(); 
     } 

     protected override void OnSleep() 
     { 
      MainPage = new HomePage(); 
     } 

     protected override void OnResume() 
     { 
      MainPage = new HomePage(); 
     } 
    } 

答えて

0

にあなたはQRコードを読み取ることZXing.Net.Mobile for Formsを使用することができます。 AppDeletage.csクラスでiOSの

ZXing.Net.Mobile.Forms.Droid.Platform.Init(); 

:MainActivity.csクラスの呼び出しでAndroid用

:このプラグインを初期化するには、このように各プロジェクト(アンドロイド、iOSの、UWP)にinitにメソッドを呼び出す必要がありますQRコードを読み取ること

ZXing.Net.Mobile.Forms.iOS.Platform.Init(); 

そして最後を呼び出す:

private async void Scan() { 
     var scanPage = new ZXingScannerPage(); 

     scanPage.OnScanResult += (result) => { 
      // Stop scanning 
      scanPage.IsScanning = false; 

      // Pop the page and show the result 
      Device.BeginInvokeOnMainThread(async() => { 
       await Navigation.PopAsync(); 
       await DisplayAlert("Scanned Barcode", result.Text, "OK"); 
      }); 
     }; 

     // Navigate to our scanner page 
     await Navigation.PushAsync(scanPage); 
} 
+0

非常に素晴らしく、正確な。一歩先を向いて、ビープ音を鳴らしたり、カードホルダーに声をかける方法はありますか? – SajidH

+0

回答として役立つ場合は、[XamarinAudioManager NuGet Package](https://www.nuget.org/packages/XamarinAudioManager)をインストールしてください。 –

関連する問題