我使用结果处理程序实现了QR代码扫描程序。它扫描得很好。但是,在第一次扫描完成后,相机卡住了。如何实现QR扫描码,以便相机继续扫描而不会卡住?
我的代码如下所示:
public class SimpleScannerFragment extends Fragment implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.scannerview, null);
mScannerView = (ZXingScannerView) v.findViewById(R.id.scanner_view);
return v;
}
@Override
public void onResume() {
super.onResume();
mScannerView.startCamera();
mScannerView.setResultHandler(this);
}
@Override
public void handleResult(Result rawResult) {
ParsedResult parserdResult = ResultParser.parseResult(rawResult);
Toast.makeText(getActivity(), "Contents = " + rawResult.getText() + ", Format = " + rawResult.getBarcodeFormat().toString(), Toast.LENGTH_SHORT).show();
}
@Override
public void onPause() {
super.onPause();
mScannerView.stopCamera();
}
}
答案 0 :(得分:4)
根据手册(https://github.com/dm77/barcodescanner),只需在处理程序中恢复你的cammera:
Math.pow(2, binaryString.length() - 1 - i)
答案 1 :(得分:1)
@viper,这对我一直都是最好的方法。
在onPostExecute
再次启动相机,然后重新启动相机预览。
如果在handleResult或onPostExecute中显示一个对话框,则Dmitri的答案可能效果不佳。
data
这会启动相机并刷新它
答案 2 :(得分:0)
您必须在暂停相机后恢复相机
测试此代码
public class SimpleScannerFragment extends Fragment implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.scannerview, null);
mScannerView = (ZXingScannerView) v.findViewById(R.id.scanner_view);
return v;
}
@Override
public void onStart() {
super.onStart();
mScannerView.startCamera();
mScannerView.setResultHandler(this);
}
@Override
public void handleResult(Result rawResult) {
ParsedResult parserdResult = ResultParser.parseResult(rawResult);
Toast.makeText(getActivity(), "Contents = " + rawResult.getText() + ", Format = " + rawResult.getBarcodeFormat().toString(), Toast.LENGTH_SHORT).show();
mScannerView.resumeCameraPreview(this);
}
@Override
public void onStop() {
mScannerView.stopCamera();
super.onStop();
}
}
答案 3 :(得分:0)
resumeCameraPreview(resultHandler: ZXingScannerView.ResultHandler)
startCamera()
两行代码将使扫描仪启动相机并再次恢复,然后在扫描后连续扫描