Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can ZXing be stopped or dispose so i can use it again?

im using ZXing.Net.Mobile for Forms like this

                    var scanPage = new ZXingScannerPage();

                    scanPage.OnScanResult += (result) => {
                        // Stop scanning
                        scanPage.IsScanning = false;
                        // Pop the page and show the result
                        Device.BeginInvokeOnMainThread(async () => {
                          //  await Navigation.PopAsync();
                            await Navigation.PushModalAsync(new Pages.DataGridPage(PladsId));

                        });
                    };

from https://components.xamarin.com/gettingstarted/zxing.net.mobile.forms

but after i have scanned once the carmera is frozen when i try again i have tried to Dispose/stop the scanner but without success

can ZXing be stopped or dispose so i can use it again ?

im using visual studio 2015 community, xamarin.Forms 2.3.3.168, Syncfusion 14.4.0.15 and ZXing.Net.Mobile 2.1.47. running it on a sony xperia z3 with Android version 6.0.1 and using API 23

Any help is deeply appreciated

like image 201
Zarp Avatar asked Feb 06 '23 10:02

Zarp


1 Answers

Found the solution....

Use IsScanning=true only once... In ScannerView Constructor or in OnAppearing of the Page..

_zxing = new ZXingScannerView
    {
        VerticalOptions = LayoutOptions.Center,
        HorizontalOptions = LayoutOptions.Center,
        HeightRequest = 250,
        WidthRequest = 250,
        IsAnalyzing = true,
        IsScanning = true,

    };

Don't write anything in OnDisappearing...

protected override void OnDisappearing()
{
   // _zxing.IsScanning = false;
    base.OnDisappearing();

}

IsAnalysing to be set false once scanning complete and should be set true in OnAppearing...

_zxing.OnScanResult += (result) =>       
Device.BeginInvokeOnMainThread(async () =>
{
     if (!string.IsNullOrWhiteSpace(result.Text))
     {
         _zxing.IsAnalyzing = false;
         await OnGettingResult(result.Text);
     }
});

protected override void OnAppearing()
{
    base.OnAppearing();
    _zxing.IsAnalyzing = true;

   //Not required if already set while intialization
   //_zxing.IsScanning = true;

}
like image 145
Ritesh Mishra Avatar answered Feb 22 '23 09:02

Ritesh Mishra