code-scanner
code-scanner copied to clipboard
java.lang.IllegalStateException: Code scanner has already been set
hello there. that's an issue while starting code scanner on fragment on 'OnCreateView' method.
CodeScannerView scannerView = view.findViewById(R.id.scanner_view); mCodeScanner = new CodeScanner(getActivity(),scannerView); mCodeScanner.setDecodeCallback(new DecodeCallback() { @Override public void onDecoded(@NonNull final Result result) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getActivity(), result.getText(), Toast.LENGTH_SHORT).show(); } }); } }); scannerView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mCodeScanner.startPreview(); } });
@babakmhz The same thing happened to me, but in my case in the onResume it sent to call the initialization of the library twice when it asked for the runtime Permissions.
Check that the initialization is not being double called