Skip to content

Commit 58dc6cf

Browse files
committed
Fix basic sample usage for Android
1 parent a2c856b commit 58dc6cf

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

readme.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ The simplest example of using ZXing.Net.Mobile looks something like this:
1010
```csharp
1111
buttonScan.Click += (sender, e) => {
1212

13-
//NOTE: On Android, you MUST pass a Context into the Constructor!
13+
#if __ANDROID__
14+
// Initialize the scanner first so it can track the current context
15+
MobileBarcodeScanner.Initialize (Application);
16+
#endif
17+
1418
var scanner = new ZXing.Mobile.MobileBarcodeScanner();
1519

16-
var result = await scanner.Scan();
20+
var result = await scanner.Scan();
1721

1822
if (result != null)
19-
Console.WriteLine("Scanned Barcode: " + result.Text);
20-
23+
Console.WriteLine("Scanned Barcode: " + result.Text);
2124
};
2225
```
2326

@@ -140,12 +143,17 @@ All of the platform samples have examples of custom overlays.
140143
By default, all barcode formats are monitored while scanning. You can change which formats to check for by passing a ZxingScanningOptions instance into the StartScanning method:
141144

142145
```csharp
146+
//NOTE: On Android you should call the initialize method with an application instance
147+
#if __ANDROID__
148+
// Initialize the scanner first so it can track the current context
149+
MobileBarcodeScanner.Initialize (Application);
150+
#endif
151+
143152
var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
144153
options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
145154
ZXing.BarcodeFormat.Ean8, ZXing.BarcodeFormat.Ean13
146155
};
147156

148-
//NOTE: On Android you MUST pass a Context into the Constructor!
149157
var scanner = new ZXing.Mobile.MobileBarcodeScanner();
150158
var result = await scanner.Scan(options);
151159
//Handle result

0 commit comments

Comments
 (0)