BarcodeDetector should only scan when a Button is clickedWhat does it means in C# : using -= operator by events?Android cameraSource.stop() causing app to freezeWhen should the volatile keyword be used in C#?Should 'using' directives be inside or outside the namespace?When should I use GC.SuppressFinalize()?When should I use a List vs a LinkedListWhen to use struct?Random number generator only generating one random numberWhen to use .First and when to use .FirstOrDefault with LINQ?decimal vs double! - Which one should I use and when?When should I use Lazy<T>?How and when to use ‘async’ and ‘await’

Pronunciation of "солнце"

What is the origin of the "being immortal sucks" trope?

Beauville-Laszlo for schemes

Can an infinite series be thought of as adding up "infinitely many" terms?

Why does '/' contain '..'?

Which version of the Pigeonhole principle is correct? One is far stronger than the other

Writing a system of Linear Equations

Persuading players to be less attached to a pre-session 0 character concept

Is it safe to unplug a blinking USB drive after 'safely' ejecting it?

Are there any “Third Order” acronyms used in space exploration?

How to make classical firearms effective on space habitats despite the coriolis effect?

Is it appropriate to CC a lot of people on an email?

Test to know when to use GLM over Linear Regression?

What does "boys rule, girls drool" mean?

Is there a theorem in Real analysis similar to Cauchy's theorem in Complex analysis?

L and epsilon factors of Gelbart-Jacquet lifts

Why is the UK still pressing on with Brexit?

Why would short-haul flights be pressurised at a higher cabin pressure?

Exam design: give maximum score per question or not?

What does this Blight Tower UI mean?

Why 1.5fill is 0pt

Delete empty subfolders, keep parent folder

Why cannot a convert make certain statements? I feel they are being pushed away at the same time respect is being given to them

Is it better to use mosfet with gate driver IC or mosfet with lower VGs on



BarcodeDetector should only scan when a Button is clicked


What does it means in C# : using -= operator by events?Android cameraSource.stop() causing app to freezeWhen should the volatile keyword be used in C#?Should 'using' directives be inside or outside the namespace?When should I use GC.SuppressFinalize()?When should I use a List vs a LinkedListWhen to use struct?Random number generator only generating one random numberWhen to use .First and when to use .FirstOrDefault with LINQ?decimal vs double! - Which one should I use and when?When should I use Lazy<T>?How and when to use ‘async’ and ‘await’






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm trying to write an app with an integrated barcode scanner.
I followed this tutorial:
https://www.c-sharpcorner.com/article/xamarin-android-qr-code-reader-by-mobile-camera/



The scan works fine and very fast (before I used ZXing.Net.Mobile and it is horrible slow).
Now I need some help to integrate that the app only detects one barcode when the user presses a button and not the whole time. Maybe a delay would solve the problem too.



protected override void OnCreate(Bundle savedInstanceState)
BarcodeFormat.QrCode)
.Build();
cameraSource = new CameraSource
.Builder(this, barcodeDetector)
.SetRequestedPreviewSize(320, 480)
.SetAutoFocusEnabled(true)
.Build();

surfaceView.Click += StartScanning;
surfaceView.Holder.AddCallback(this);
//barcodeDetector.SetProcessor(this);



private void StartScanning(object sender, EventArgs e)

barcodeDetector.SetProcessor(this);



public void ReceiveDetections(Detections detections)

SparseArray qrcodes = detections.DetectedItems;
if (qrcodes.Size() != 0)

txtResult.Post(() =>
//Vibrator vibrator = (Vibrator)GetSystemService(Context.VibratorService);
//vibrator.Vibrate(1000);
txtResult.Text = ((Barcode)qrcodes.ValueAt(0)).RawValue;
);




At the moment the user presses the SurfaceView and the scanner starts and never stops.



Is it possible, that it just scans one after pressing the "button"?



r3d007










share|improve this question
























  • Have a look at this post may help.

    – Jack Hua - MSFT
    Mar 29 at 6:06

















1















I'm trying to write an app with an integrated barcode scanner.
I followed this tutorial:
https://www.c-sharpcorner.com/article/xamarin-android-qr-code-reader-by-mobile-camera/



The scan works fine and very fast (before I used ZXing.Net.Mobile and it is horrible slow).
Now I need some help to integrate that the app only detects one barcode when the user presses a button and not the whole time. Maybe a delay would solve the problem too.



protected override void OnCreate(Bundle savedInstanceState)
BarcodeFormat.QrCode)
.Build();
cameraSource = new CameraSource
.Builder(this, barcodeDetector)
.SetRequestedPreviewSize(320, 480)
.SetAutoFocusEnabled(true)
.Build();

surfaceView.Click += StartScanning;
surfaceView.Holder.AddCallback(this);
//barcodeDetector.SetProcessor(this);



private void StartScanning(object sender, EventArgs e)

barcodeDetector.SetProcessor(this);



public void ReceiveDetections(Detections detections)

SparseArray qrcodes = detections.DetectedItems;
if (qrcodes.Size() != 0)

txtResult.Post(() =>
//Vibrator vibrator = (Vibrator)GetSystemService(Context.VibratorService);
//vibrator.Vibrate(1000);
txtResult.Text = ((Barcode)qrcodes.ValueAt(0)).RawValue;
);




At the moment the user presses the SurfaceView and the scanner starts and never stops.



Is it possible, that it just scans one after pressing the "button"?



r3d007










share|improve this question
























  • Have a look at this post may help.

    – Jack Hua - MSFT
    Mar 29 at 6:06













1












1








1


1






I'm trying to write an app with an integrated barcode scanner.
I followed this tutorial:
https://www.c-sharpcorner.com/article/xamarin-android-qr-code-reader-by-mobile-camera/



The scan works fine and very fast (before I used ZXing.Net.Mobile and it is horrible slow).
Now I need some help to integrate that the app only detects one barcode when the user presses a button and not the whole time. Maybe a delay would solve the problem too.



protected override void OnCreate(Bundle savedInstanceState)
BarcodeFormat.QrCode)
.Build();
cameraSource = new CameraSource
.Builder(this, barcodeDetector)
.SetRequestedPreviewSize(320, 480)
.SetAutoFocusEnabled(true)
.Build();

surfaceView.Click += StartScanning;
surfaceView.Holder.AddCallback(this);
//barcodeDetector.SetProcessor(this);



private void StartScanning(object sender, EventArgs e)

barcodeDetector.SetProcessor(this);



public void ReceiveDetections(Detections detections)

SparseArray qrcodes = detections.DetectedItems;
if (qrcodes.Size() != 0)

txtResult.Post(() =>
//Vibrator vibrator = (Vibrator)GetSystemService(Context.VibratorService);
//vibrator.Vibrate(1000);
txtResult.Text = ((Barcode)qrcodes.ValueAt(0)).RawValue;
);




At the moment the user presses the SurfaceView and the scanner starts and never stops.



Is it possible, that it just scans one after pressing the "button"?



r3d007










share|improve this question














I'm trying to write an app with an integrated barcode scanner.
I followed this tutorial:
https://www.c-sharpcorner.com/article/xamarin-android-qr-code-reader-by-mobile-camera/



The scan works fine and very fast (before I used ZXing.Net.Mobile and it is horrible slow).
Now I need some help to integrate that the app only detects one barcode when the user presses a button and not the whole time. Maybe a delay would solve the problem too.



protected override void OnCreate(Bundle savedInstanceState)
BarcodeFormat.QrCode)
.Build();
cameraSource = new CameraSource
.Builder(this, barcodeDetector)
.SetRequestedPreviewSize(320, 480)
.SetAutoFocusEnabled(true)
.Build();

surfaceView.Click += StartScanning;
surfaceView.Holder.AddCallback(this);
//barcodeDetector.SetProcessor(this);



private void StartScanning(object sender, EventArgs e)

barcodeDetector.SetProcessor(this);



public void ReceiveDetections(Detections detections)

SparseArray qrcodes = detections.DetectedItems;
if (qrcodes.Size() != 0)

txtResult.Post(() =>
//Vibrator vibrator = (Vibrator)GetSystemService(Context.VibratorService);
//vibrator.Vibrate(1000);
txtResult.Text = ((Barcode)qrcodes.ValueAt(0)).RawValue;
);




At the moment the user presses the SurfaceView and the scanner starts and never stops.



Is it possible, that it just scans one after pressing the "button"?



r3d007







c# xamarin.android






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 12:59









r3d007r3d007

287 bronze badges




287 bronze badges















  • Have a look at this post may help.

    – Jack Hua - MSFT
    Mar 29 at 6:06

















  • Have a look at this post may help.

    – Jack Hua - MSFT
    Mar 29 at 6:06
















Have a look at this post may help.

– Jack Hua - MSFT
Mar 29 at 6:06





Have a look at this post may help.

– Jack Hua - MSFT
Mar 29 at 6:06












2 Answers
2






active

oldest

votes


















1
















1 Uncomment this line in OnCreate method



barcodeDetector.SetProcessor(this);


2 Remove or comment this line from SurfaceCreated and OnRequestPermissionsResult methods



cameraSource.Start(surfaceView.Holder);


3 Your StartScanning method should call the Start



private void StartScanning(object sender, EventArgs e)

cameraSource.Start(surfaceView.Holder);



4 Once you read and validate a code, stop the scanner



public void ReceiveDetections(Detections detections)

SparseArray qrcodes = detections.DetectedItems;
if (qrcodes.Size() != 0)

txtResult.Post(() =>
//Vibrator vibrator = (Vibrator)GetSystemService(Context.VibratorService);
//vibrator.Vibrate(1000);
txtResult.Text = ((Barcode)qrcodes.ValueAt(0)).RawValue;
);

using (var h = new Handler (Looper.MainLooper))
h.Post (() =>
cameraSource.Stop();
);





To prevent crashes, consider also to hide or disable the button until you get the camera permissions, and when the scanner is already started.






share|improve this answer



























  • Tried it this way and the first time i click the button, it scans and stops scanning after it found a result. But when I click the button again, it doesn't start scanning and no other button is working. Not even the Android Back button is working then.

    – r3d007
    Mar 28 at 14:41






  • 1





    @r3d007 Check the update, the crash is caused when it stops, not when you try to start again, the code inside the receiveDetections method is running on a different thread so, you need to post the cameraSource.Stop() from a handler

    – Daniel Brughera
    Mar 28 at 15:09



















0
















You need add this after scan process triggered. "-" operator must be added to prevent non-stop working.You plugged-in event in this line



//adds the handler
surfaceView.Click += StartScanning;


after that you need this.



 // removes the handler
surfaceView.Click -= StartScanning;


Also look here






share|improve this answer



























  • This removes the EventHandler from the SurfaceView and does not stop the scanning process.

    – r3d007
    Mar 28 at 13:11











  • where is your scan process can you share it ?

    – Batuhan
    Mar 28 at 13:13













Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55398303%2fbarcodedetector-should-only-scan-when-a-button-is-clicked%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1
















1 Uncomment this line in OnCreate method



barcodeDetector.SetProcessor(this);


2 Remove or comment this line from SurfaceCreated and OnRequestPermissionsResult methods



cameraSource.Start(surfaceView.Holder);


3 Your StartScanning method should call the Start



private void StartScanning(object sender, EventArgs e)

cameraSource.Start(surfaceView.Holder);



4 Once you read and validate a code, stop the scanner



public void ReceiveDetections(Detections detections)

SparseArray qrcodes = detections.DetectedItems;
if (qrcodes.Size() != 0)

txtResult.Post(() =>
//Vibrator vibrator = (Vibrator)GetSystemService(Context.VibratorService);
//vibrator.Vibrate(1000);
txtResult.Text = ((Barcode)qrcodes.ValueAt(0)).RawValue;
);

using (var h = new Handler (Looper.MainLooper))
h.Post (() =>
cameraSource.Stop();
);





To prevent crashes, consider also to hide or disable the button until you get the camera permissions, and when the scanner is already started.






share|improve this answer



























  • Tried it this way and the first time i click the button, it scans and stops scanning after it found a result. But when I click the button again, it doesn't start scanning and no other button is working. Not even the Android Back button is working then.

    – r3d007
    Mar 28 at 14:41






  • 1





    @r3d007 Check the update, the crash is caused when it stops, not when you try to start again, the code inside the receiveDetections method is running on a different thread so, you need to post the cameraSource.Stop() from a handler

    – Daniel Brughera
    Mar 28 at 15:09
















1
















1 Uncomment this line in OnCreate method



barcodeDetector.SetProcessor(this);


2 Remove or comment this line from SurfaceCreated and OnRequestPermissionsResult methods



cameraSource.Start(surfaceView.Holder);


3 Your StartScanning method should call the Start



private void StartScanning(object sender, EventArgs e)

cameraSource.Start(surfaceView.Holder);



4 Once you read and validate a code, stop the scanner



public void ReceiveDetections(Detections detections)

SparseArray qrcodes = detections.DetectedItems;
if (qrcodes.Size() != 0)

txtResult.Post(() =>
//Vibrator vibrator = (Vibrator)GetSystemService(Context.VibratorService);
//vibrator.Vibrate(1000);
txtResult.Text = ((Barcode)qrcodes.ValueAt(0)).RawValue;
);

using (var h = new Handler (Looper.MainLooper))
h.Post (() =>
cameraSource.Stop();
);





To prevent crashes, consider also to hide or disable the button until you get the camera permissions, and when the scanner is already started.






share|improve this answer



























  • Tried it this way and the first time i click the button, it scans and stops scanning after it found a result. But when I click the button again, it doesn't start scanning and no other button is working. Not even the Android Back button is working then.

    – r3d007
    Mar 28 at 14:41






  • 1





    @r3d007 Check the update, the crash is caused when it stops, not when you try to start again, the code inside the receiveDetections method is running on a different thread so, you need to post the cameraSource.Stop() from a handler

    – Daniel Brughera
    Mar 28 at 15:09














1














1










1









1 Uncomment this line in OnCreate method



barcodeDetector.SetProcessor(this);


2 Remove or comment this line from SurfaceCreated and OnRequestPermissionsResult methods



cameraSource.Start(surfaceView.Holder);


3 Your StartScanning method should call the Start



private void StartScanning(object sender, EventArgs e)

cameraSource.Start(surfaceView.Holder);



4 Once you read and validate a code, stop the scanner



public void ReceiveDetections(Detections detections)

SparseArray qrcodes = detections.DetectedItems;
if (qrcodes.Size() != 0)

txtResult.Post(() =>
//Vibrator vibrator = (Vibrator)GetSystemService(Context.VibratorService);
//vibrator.Vibrate(1000);
txtResult.Text = ((Barcode)qrcodes.ValueAt(0)).RawValue;
);

using (var h = new Handler (Looper.MainLooper))
h.Post (() =>
cameraSource.Stop();
);





To prevent crashes, consider also to hide or disable the button until you get the camera permissions, and when the scanner is already started.






share|improve this answer















1 Uncomment this line in OnCreate method



barcodeDetector.SetProcessor(this);


2 Remove or comment this line from SurfaceCreated and OnRequestPermissionsResult methods



cameraSource.Start(surfaceView.Holder);


3 Your StartScanning method should call the Start



private void StartScanning(object sender, EventArgs e)

cameraSource.Start(surfaceView.Holder);



4 Once you read and validate a code, stop the scanner



public void ReceiveDetections(Detections detections)

SparseArray qrcodes = detections.DetectedItems;
if (qrcodes.Size() != 0)

txtResult.Post(() =>
//Vibrator vibrator = (Vibrator)GetSystemService(Context.VibratorService);
//vibrator.Vibrate(1000);
txtResult.Text = ((Barcode)qrcodes.ValueAt(0)).RawValue;
);

using (var h = new Handler (Looper.MainLooper))
h.Post (() =>
cameraSource.Stop();
);





To prevent crashes, consider also to hide or disable the button until you get the camera permissions, and when the scanner is already started.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 28 at 15:06

























answered Mar 28 at 14:02









Daniel BrugheraDaniel Brughera

1,4961 gold badge3 silver badges14 bronze badges




1,4961 gold badge3 silver badges14 bronze badges















  • Tried it this way and the first time i click the button, it scans and stops scanning after it found a result. But when I click the button again, it doesn't start scanning and no other button is working. Not even the Android Back button is working then.

    – r3d007
    Mar 28 at 14:41






  • 1





    @r3d007 Check the update, the crash is caused when it stops, not when you try to start again, the code inside the receiveDetections method is running on a different thread so, you need to post the cameraSource.Stop() from a handler

    – Daniel Brughera
    Mar 28 at 15:09


















  • Tried it this way and the first time i click the button, it scans and stops scanning after it found a result. But when I click the button again, it doesn't start scanning and no other button is working. Not even the Android Back button is working then.

    – r3d007
    Mar 28 at 14:41






  • 1





    @r3d007 Check the update, the crash is caused when it stops, not when you try to start again, the code inside the receiveDetections method is running on a different thread so, you need to post the cameraSource.Stop() from a handler

    – Daniel Brughera
    Mar 28 at 15:09

















Tried it this way and the first time i click the button, it scans and stops scanning after it found a result. But when I click the button again, it doesn't start scanning and no other button is working. Not even the Android Back button is working then.

– r3d007
Mar 28 at 14:41





Tried it this way and the first time i click the button, it scans and stops scanning after it found a result. But when I click the button again, it doesn't start scanning and no other button is working. Not even the Android Back button is working then.

– r3d007
Mar 28 at 14:41




1




1





@r3d007 Check the update, the crash is caused when it stops, not when you try to start again, the code inside the receiveDetections method is running on a different thread so, you need to post the cameraSource.Stop() from a handler

– Daniel Brughera
Mar 28 at 15:09






@r3d007 Check the update, the crash is caused when it stops, not when you try to start again, the code inside the receiveDetections method is running on a different thread so, you need to post the cameraSource.Stop() from a handler

– Daniel Brughera
Mar 28 at 15:09














0
















You need add this after scan process triggered. "-" operator must be added to prevent non-stop working.You plugged-in event in this line



//adds the handler
surfaceView.Click += StartScanning;


after that you need this.



 // removes the handler
surfaceView.Click -= StartScanning;


Also look here






share|improve this answer



























  • This removes the EventHandler from the SurfaceView and does not stop the scanning process.

    – r3d007
    Mar 28 at 13:11











  • where is your scan process can you share it ?

    – Batuhan
    Mar 28 at 13:13















0
















You need add this after scan process triggered. "-" operator must be added to prevent non-stop working.You plugged-in event in this line



//adds the handler
surfaceView.Click += StartScanning;


after that you need this.



 // removes the handler
surfaceView.Click -= StartScanning;


Also look here






share|improve this answer



























  • This removes the EventHandler from the SurfaceView and does not stop the scanning process.

    – r3d007
    Mar 28 at 13:11











  • where is your scan process can you share it ?

    – Batuhan
    Mar 28 at 13:13













0














0










0









You need add this after scan process triggered. "-" operator must be added to prevent non-stop working.You plugged-in event in this line



//adds the handler
surfaceView.Click += StartScanning;


after that you need this.



 // removes the handler
surfaceView.Click -= StartScanning;


Also look here






share|improve this answer















You need add this after scan process triggered. "-" operator must be added to prevent non-stop working.You plugged-in event in this line



//adds the handler
surfaceView.Click += StartScanning;


after that you need this.



 // removes the handler
surfaceView.Click -= StartScanning;


Also look here







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 28 at 13:12

























answered Mar 28 at 13:06









BatuhanBatuhan

3923 silver badges14 bronze badges




3923 silver badges14 bronze badges















  • This removes the EventHandler from the SurfaceView and does not stop the scanning process.

    – r3d007
    Mar 28 at 13:11











  • where is your scan process can you share it ?

    – Batuhan
    Mar 28 at 13:13

















  • This removes the EventHandler from the SurfaceView and does not stop the scanning process.

    – r3d007
    Mar 28 at 13:11











  • where is your scan process can you share it ?

    – Batuhan
    Mar 28 at 13:13
















This removes the EventHandler from the SurfaceView and does not stop the scanning process.

– r3d007
Mar 28 at 13:11





This removes the EventHandler from the SurfaceView and does not stop the scanning process.

– r3d007
Mar 28 at 13:11













where is your scan process can you share it ?

– Batuhan
Mar 28 at 13:13





where is your scan process can you share it ?

– Batuhan
Mar 28 at 13:13


















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55398303%2fbarcodedetector-should-only-scan-when-a-button-is-clicked%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현