I am working on project which requires qr scanning and I use zxing library. It works fine on button click event. But I want to scan QR code in the 1st UI when UI loaded (probably on create event). Can someone help me with this.
@MuthuMK After your initialized your views in OnCreate you could call your button click event. Therefor you need to change the way you attach it to the button.
btnCamera.Click += async (sender, e) => { var scanner = new ZXing.Mobile.MobileBarcodeScanner(); var result = await scanner.Scan(); string qrCode = result.ToString(); }
Becomes:
btnCamera.Click += btnCamera_Click; async void btnCamera_Click(object sender, EventArgs e) { var scanner = new ZXing.Mobile.MobileBarcodeScanner(); var result = await scanner.Scan(); string qrCode = result.ToString(); }
Now you can call 'btnCamera_Click(this, EventArgs.Empty);' inside your OnCreate method.
Answers
Creating your reference to views in OnCreate is totally ok. If you just want to start the scan process move your code from your button inside the OnCreate method. To help you any further I need to see some code.
btnCamera.Click += async (sender, e) =>
{
}
This is the button click code which is directly taking qr scan from the zxing libry. What I wnat is having button and the scanning window in same screen
@MuthuMK After your initialized your views in OnCreate you could call your button click event. Therefor you need to change the way you attach it to the button.
Becomes:
Now you can call 'btnCamera_Click(this, EventArgs.Empty);' inside your OnCreate method.