英语不好,我很抱歉。我使用Zxing https://github.com/Redth/ZXing.Net.Mobile的文档在xamarin.android上实现了条形码检测器应用程序。它在具有android 6.0的手机上可以正常工作并检测各种条形码,但是在具有android 7.0或更高版本的手机上,它代替相机显示的页面具有我的默认颜色主题,并显示我在布局中具有的按钮和textview。如果我在没有任何照相机的情况下盲目地将条形码放在照相机前面,则可以检测到它。所以我唯一的问题是我看不到相机,但它以某种方式工作。我搜索了整个网站,但找不到任何有用的东西。是的,我在清单中拥有相机和手电筒的权限。这是我的权限代码:
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
global::ZXing.Net.Mobile.Android.PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
protected override void OnResume()
{
base.OnResume();
if (ZXing.Net.Mobile.Android.PermissionsHandler.NeedsPermissionRequest(this))
ZXing.Net.Mobile.Android.PermissionsHandler.RequestPermissionsAsync(this);
}
这是我用于初始化扫描仪的代码
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
MobileBarcodeScanner.Initialize(Application);
SetContentView(Resource.Layout.xlRealMain);
scanner = new MobileBarcodeScanner();
this.Window.AddFlags(WindowManagerFlags.Fullscreen);
btnbarcode = FindViewById<Button>(Resource.Id.barcode);
btnbarcode .Click += async delegate {
//Tell our scanner to use the default overlay
scanner.UseCustomOverlay = false;
//Start scanning
var result = await scanner.Scan();
HandleScanResult(result);
}
void HandleScanResult (ZXing.Result result)
{
string msg = "";
if (result != null && !string.IsNullOrEmpty(result.Text))
msg = "Found Barcode: " + result.Text;
else
msg = "Scanning Canceled!";
this.RunOnUiThread(() => Toast.MakeText(this, msg,
ToastLength.Short).Show());
}