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;
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
add a comment
|
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
Have a look at this post may help.
– Jack Hua - MSFT
Mar 29 at 6:06
add a comment
|
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
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
c# xamarin.android
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
add a comment
|
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
add a comment
|
2 Answers
2
active
oldest
votes
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.
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
add a comment
|
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
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
add a comment
|
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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 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.
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
add a comment
|
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.
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
add a comment
|
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.
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.
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
add a comment
|
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
add a comment
|
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
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
add a comment
|
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
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
add a comment
|
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
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
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
add a comment
|
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
add a comment
|
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Have a look at this post may help.
– Jack Hua - MSFT
Mar 29 at 6:06