當前正試圖使用ZXing Mobile爲Xamarin Forms構建應用程序。在Xamarin Forms應用程序中使用ZXing Mobile
編譯的代碼沒有問題。但是,試圖將Android設備上運行的時候,我得到了以下錯誤:
An unhandled exception occcured.
日誌顯示以下內容:
[0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText'
[0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText'
[0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton'
[0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText'
[0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText'
[0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton'
我這是怎麼實現的:
scanButton.Clicked += async (sender, args) =>
{
var options = new MobileBarcodeScanningOptions
{
AutoRotate = false,
UseFrontCameraIfAvailable = false,
TryHarder = true
};
var scanPage = new ZXingScannerPage(options)
{
DefaultOverlayTopText = "Align the barcode within the frame",
DefaultOverlayBottomText = string.Empty,
DefaultOverlayShowFlashButton = true
};
// Navigate to our scanner page
await Navigation.PushAsync(scanPage);
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");
});
};
};
還增加以下是Android的主要活動,位於Xamarin自己的Init上方:
ZXing.Net.Mobile.Forms.Android.Platform.Init();
任何幫助表示讚賞。謝謝。
什麼版本的斑馬線您使用的是? Nuget或組件?你是否也要求獲得相機的許可? – apineda
該版本是2.2.9。通過Nuget安裝。是的,權限被添加到'AndroidManifest.xml'上。 – ipohfly