Reputation: 125
i'm desperately trying to get ZXing.Mobile working within Xamarin VS2012 C# but I'm struggling to find anything in the net to answer my question! :(
This is the code I have:
bnGetComp.Click += (sender, e) =>
{
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
scanner.Scan().ContinueWith((t) =>
{
if (t.IsFaulted)
{
aTbCompName.Text = t.Exception.ToString();
}
else if (t.Result != null)
{
aTbCompName.Text = t.Result.Text;
}
});
};
My phone starts the scanner, then scans the barcode, then just empties the text box, I've even tried making it just fill aTbCompName.text with a string value i.e. "TEST" and it still empties it! I can't understand what its doing and I can't stick a break point on it as that doesn't seem to do buggar all in Xamarin...
(Phone is a Samsung Galaxy Note N7000 running the official JB 4.1.2)
Can anyone help?
Update:
I've been playing around with it and it does work if I rotate the phone afterwards, any idea why rotating after the barcode has been scanned would then finish the process off and put the result into a text box?
Upvotes: 3
Views: 2855
Reputation: 1211
This may or may not work but I have my code running the updates to the UI on the UI thread... See code below...
scanner.Scan().ContinueWith(t =>
RunOnUiThread(
() =>
{
searchBar.Text = t.Result.Text;
var intent = new Intent(this, typeof(SearchResultsActivity));
intent.PutExtra("Description", searchBar.Text);
StartActivity(intent);
}));
Upvotes: 3