I'm using ZXing in a Forms app via DI - it works great on the iOS side, but hangs in the ZXing UI on the Android side. Neither the completion nor the error handler are being called. In iOS it scans succesfully and returns to the prior view automatically.
the Interface:
public interface IBarCodeScanner {
void Read(Action<string> onRead, Action<Exception> onError = null);
}
the Android implementation
[assembly: Dependency (typeof (BarCodeScanner_A))]
namespace DAI.POC.Android
{
public class BarCodeScanner_A : Java.Lang.Object, IBarCodeScanner
{
public BarCodeScanner_A ()
{
}
public void Read(Action<string> onRead, Action<Exception> onError) {
this.ReadAsync()
.ContinueWith(x => {
if (x.Exception == null)
{
Console.WriteLine("Scanned: " + x.Result);
onRead(x.Result);
}
else if (onError != null)
{
Console.WriteLine("Scan Error: " + x.Exception.InnerException.Message);
onError(x.Exception);
}
});
}
public async Task<string> ReadAsync() {
var scanner = new MobileBarcodeScanner(Forms.Context) { UseCustomOverlay = false };
var result = await scanner.Scan();
return (result == null || String.IsNullOrWhiteSpace(result.Text)
? string.Empty
: result.Text
);
}
}
}