2017-11-12 13 views
0

아래 코드를 사용하여 Xamarin의 QR 코드를 스캔합니다. 현재 삼성 갤럭시 (Android)에서 테스트 중이며 스트리밍 카메라를 볼 수는 있지만 QR 코드는 스캔하지 않습니다.ZXing이 Android (Xamarin 앱)에서 스캔하지 않습니다.

QR 스캔 결과를 얻으려면 어떻게해야합니까?

public void Scan() 
{ 
try 
{ 
scanner.Options = new MobileBarcodeScanningOptions() 
{ 
UseFrontCameraIfAvailable = false, //update later to come from settings 
PossibleFormats = new List(), 
TryHarder = true, 
AutoRotate = false, 
TryInverted = true, 
DelayBetweenContinuousScans = 2000, 
}; 

    scanner.VerticalOptions = LayoutOptions.FillAndExpand; 
    scanner.HorizontalOptions = LayoutOptions.FillAndExpand; 

    // scanner.IsVisible = false; 

    scanner.Options.PossibleFormats.Add(BarcodeFormat.QR_CODE); 
    // scanner.Options.PossibleFormats.Add(BarcodeFormat.DATA_MATRIX); 
    // scanner.Options.PossibleFormats.Add(BarcodeFormat.EAN_13); 


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

     if (scanner.IsScanning) 
     { 
      scanner.AutoFocus(); 
     } 

     // Pop the page and show the result 
     Device.BeginInvokeOnMainThread(async() => { 
      if (result != null) 
      { 
       await DisplayAlert("Scan Value", result.Text, "OK"); 
      } 
     }); 
    }; 

    mainGrid.Children.Add(scanner, 0, 1); 
} 
catch (Exception ex) 
{ 
    DisplayAlert("Scan Value", ex.ToString(), "Error"); 
} 
} 

답변

0

어쩌면 당신은 잘못된 이벤트 핸들러를 사용하거나 이벤트를 누락, 또한 카메라는 결코 초점을 맞추고 없습니다 :

조건이 때문에이 코드 조각에, 결코 사실이다 :

scanner.IsScanning = false; 

    if (scanner.IsScanning) 
    { 
     scanner.AutoFocus(); 
    } 
+0

나는 아래 코드도 시도했지만 아무것도 스캔하지 않았다. scanner.OnScanResult + = (result) => { if (scanner.IsScanning) { scanner.AutoFocus(); } // 페이지를 팝업 및 결과 Device.BeginInvokeOnMainThread (비동기() => { 경우 (결과를 보여! = null이) { 이 DisplayAlert ("스캔 값"기다리고, result.Text, "OK"); } }); }; –

+0

코드 예를 온라인으로 작업 예제 코드와 차별화 시키거나 작동중인 프로젝트를 다운로드하여 다른 점을 파악할 수 있습니다. –

+0

실제로, 그게 내가 한 일이지만 나를 위해 일하지 않았다. –