0
我正嘗試使用xamarin格式的andorid設備上的Zxing代碼掃描儀。 創建了一個按鈕來打開Zxing掃描儀頁面。Zxing使用Xamarin.Forms的Android設備上的條碼掃描器
但是,當我這樣寫。如果我將它移動到同步方式,我得到這個錯誤
但是:
System.InvalidOperationException:未在Android的全球支持PushAsync,請使用NavigationPage其發送到我的unhandel exceptoin。
附着我的代碼:
private void goToScan()
{
var scanPage = new ZXingScannerPage();
scanPage.OnScanResult += (result) => {
// Stop scanning
scanPage.IsScanning = false;
// Pop the page and show the result
Device.BeginInvokeOnMainThread(() => {
Navigation.PopAsync();
DisplayAlert("Scanned Barcode", result.Text, "OK");
});
};
// Navigate to our scanner page
Navigation.PushAsync(scanPage);
}
}
,如果我改變Navagation.push異步到PushModalAsync這樣的: Navigation.PushModalAsync(scanPage);
我移動到Zxing掃描儀頁面,但它沒有開始掃描。 (crusior事件不動
我主要的Andorid活動看起來是這樣的:
[Activity(Label = "QRCode4", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
ZXing.Net.Mobile.Forms.Android.Platform.Init();
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
global::ZXing.Net.Mobile.Forms.Android.PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
appericate任何幫助的感謝
由於這是在解決我的問題!去ŧ o詳細瞭解Xamarin表單頁面。 –