【发布时间】:2014-05-26 01:57:07
【问题描述】:
我目前正在尝试将this 组件实现到我用 Xamarins mono for andriod 构建的 android 应用程序中。
我遇到了这个问题,我无法从 scanner.Scan(); 方法返回任何结果,扫描仪启动并且没有任何反应?!
所以我尝试从github 下载示例项目,当我尝试使用那里提供的示例代码扫描条形码时,同样的问题。它不会着火。下面是一些负责启动扫描器和处理结果的代码:
public async void ScanArticleNumber()
{
//Tell our scanner to use the default overlay
scanner.UseCustomOverlay = false;
//We can customize the top and bottom text of the default overlay
scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away";
scanner.BottomText = "Wait for the barcode to automatically scan!";
//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!";
Activity.RunOnUiThread(() =>
{
Toast.MakeText(Activity.BaseContext, msg, ToastLength.Short).Show();
});
}
即使我用相机拍摄大量条形码,代码也永远不会到达 HandleScanResult 方法。
有什么想法吗?
【问题讨论】:
-
也许是个愚蠢的问题,但您是通过模拟器还是通过连接的移动设备进行调试?扫描是否完成(但从未点击
HandleScanResult) - 意思是,扫描仪 UI 是否关闭并将您返回到应用程序? -
我在移动设备上调试。什么都没有发生,这意味着在我关闭扫描仪之前我不会返回到应用程序。
-
如果我没看错,听起来扫描仪永远不会捕获条形码。只是为了消除显而易见的问题,您是否已将相机权限添加到您的应用中?
-
这些权限我已经添加了
标签: c# mono xamarin.android xamarin barcode-scanner