1
Reply

How to initialize bar code scanner on App startup.

Sajid Hussain

Sajid Hussain

Dec 21 2017 12:35 AM
160
 I have a requirement for my xamarin cross platform application that as soon as app start up .QR Scanner set in to read the code. on completing scanning a beep will be ring up.and app again ready for next scanning how can i get this done. what i have done is on button click scanner start, its read code, then i have to press button again to start it again.
 
  1. public HomePage()  
  2.         {  
  3.             Button scanBtn = new Button  
  4.             {  
  5.                 Text = "Scan Barcode",  
  6.                 HorizontalOptions = LayoutOptions.FillAndExpand,  
  7.             };  
  8.   
  9.             scanBtn.Clicked += async (sender, args) =>  
  10.             {  
  11.                 var scanResult = await Acr.BarCodes.BarCodes.Instance.Read();  
  12.                 if (!scanResult.Success)  
  13.                 {  
  14.                     await this.DisplayAlert("Alert ! ""Sorry ! \n Failed to read the Barcode !""OK");  
  15.                 }  
  16.                 else  
  17.                 {  
  18.                     var endpoint = new EndpointAddress("http://192.168.15.33/SMS/WebServices/SMSService.svc");  
  19.                     var binding = new BasicHttpBinding  
  20.                     {  
  21.                         Name = "basicHttpBinding",  
  22.                         MaxBufferSize = 2147483647,  
  23.                         MaxReceivedMessageSize = 2147483647  
  24.                     };  
  25.   
  26.                     TimeSpan timeout = new TimeSpan(0, 0, 30);  
  27.                     binding.SendTimeout = timeout;  
  28.                     binding.OpenTimeout = timeout;  
  29.                     binding.ReceiveTimeout = timeout;  
  30.   
  31.                     _client = new SMSServiceClient(binding, endpoint);  
  32.                     _client.ValidateStudentAsync("123-admin");  
  33.                     _client.ValidateStudentCompleted += _client_ValidateStudentCompleted; ;  
  34.                     // await this.DisplayAlert("Scan Successful !", String.Format("Barcode Format : {0} \n Barcode Value : {1}", scanResult.Format, scanResult.Code), "OK");  
  35.                 }  
  36.             };  
  37.   
  38.             Content = new StackLayout  
  39.             {  
  40.                 Children = {  
  41.                     scanBtn  
  42.                 }  
  43.             };  
  44.         }  
 

Answers (1)