Closed MrSilverstein closed 3 years ago
call qReader.stop()
after first scan.
and use qReader.start()
when need to start scanning again.
private void SetupQREader() { qrEader = new QREader.Builder(this, id_SurfaceView, new QRDataListener() { @Override public void onDetected(final String data) { Log.d("QREader", "Value : " + data);
result.post(new Runnable() {
@Override
public void run() {
String msg;
result.setText(data);
qrEader.stop();
msg = result.getText().toString();
Log.e("XXXXX", msg);
Intent intent = new Intent(ac, QrCodeResult.class);
intent.putExtra("RESULT", msg);
startActivity(intent);
}
});
}
}).facing(QREader.BACK_CAM)
.enableAutofocus(true)
.height(id_SurfaceView.getHeight())
.width(id_SurfaceView.getWidth())
.build();
}
still getting Log two times ? why ? not understanding. and what is the use of qrEader.wait(); and how do i use and where to use?
call
qReader.stop()
after first scan. and useqReader.start()
when need to start scanning again.
public void onDetected(final String data) {
Log.d("QREader", "Value : " + data);
Gson Gson = new Gson();
try {
QrCodeMessage qrCodeMessage = Gson.fromJson(data, QrCodeMessage.class);
if(qrCodeMessage!=null){
if(qrCodeMessage.company.equals("MyTestData")){
Log.d(TAG,"Valid QR code");
qrEader.stop();
}
}
}
catch (Exception e){
Log.d(TAG,"Couldn't parse");
}
}
@Override
public void onResume() {
super.onResume();
qrEader.initAndStart(mySurfaceView);
qrEader.start();
mySurfaceView.setOnClickListener((click)->{
qrEader.start();
});
}
onclick throws java.lang.IllegalStateException: Camera already started!
but It Doesn't scan again. Any idea how to fix this ?
@trix0 u start it before click, why start it again surround it with try /catch
Yes, when I find correct QR code, I stop it in the callback. If the QR code is not valid I want to click on window and start it again. Moment I click on window I get an error. If I do check if camera is running, it won't work at all.
First start in on resume is when window is loaded or no?
I understand that if I put it inside try catch it won't kill my app but it will not start scanning again.
On Fri, 4 Sep 2020, 16.43 Mahmoud Mabrok Fouad, notifications@github.com wrote:
@trix0 https://github.com/trix0 u start it before click, why start it again surround it with try /catch
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nisrulz/qreader/issues/64#issuecomment-687190633, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFZ7IXJ3W35YA5JUWB24WLTSED4KZANCNFSM4HDKM63Q .
@trix0
with try and catch
it will first try to start
if it failed which mean it already started
so catch will be called
so app is safe and also app function is right
The behavior is correct. The library when it was initially written didn't allow for restarting without stopping it. This issue is too old now and the library would undergo upgrades soon. Open a new one if the issue persists.
As in the examples, the QREeader reads continous. When I once read
Here it prints continueous the read data object as long as I hold the scanner to the qr code. I would like to call printReadQrCode(data) only once it was read successfully.. then stop the qreader and resume if required.
also
wont help, since I do not have any Views and I do not want to add artificially some View elements..