如何关闭ZXing QrCode自定义视图

时间:2016-10-16 22:38:40

标签: android zxing

我使用ZXing库来扫描QrCode。 从抽屉菜单中我调用一个新的意图,我用自定义视图开始自定义活动扫描:

  

integrator.setCaptureActivity(QrCodeCaptureActivity.class);

public class QrCodeActivity extends AppCompatActivity {

                private static final String TAG = "QrCodeActivity";
                private String message = "";

                @Override
                protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);

                    setContentView(R.layout.activity_qrcode);

                    setToolbar();
                    scanBarcodeCustomLayout();

                }

                /** Set la toolbar */
                private void setToolbar(){
                  final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
                  setSupportActionBar(toolbar);
                  getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                }

                public void scanBarcodeCustomLayout() {
                    IntentIntegrator integrator = new IntentIntegrator(this);
                    integrator.setOrientationLocked(false);
                    integrator.setCaptureActivity(QrCodeCaptureActivity.class);
                    integrator.initiateScan();
                }

                @Override
                protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
                    if(result != null) {
                        message = result.getContents();
                        if(result.getContents() == null) {
                            Log.d(TAG, "Cancelled scan");
                            finish();
                            // Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
                        } else {
                            showConfirmDialog();
                            Log.d(TAG, "Scanned: " + result.getContents());
                            // Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
                        }
                    } else {
                        // This is important, otherwise the result will not be passed to the fragment
                        super.onActivityResult(requestCode, resultCode, data);
                    }
                }

                private void showConfirmDialog(){
                    Intent confirmIntent = new Intent(QrCodeActivity.this, QrCodeConfirmActivity.class);
                    confirmIntent.putExtra(Constants.QR_CODE_MESSAGE, message);
                    startActivity(confirmIntent);
                }
}

捕获活动如下所示:

public class QrCodeCaptureActivity extends CaptureActivity {
    @Override
    protected DecoratedBarcodeView initializeContent() {
        setContentView(R.layout.capture_small);           
        return (DecoratedBarcodeView)findViewById(R.id.zxing_barcode_scanner);
    }
}

您可以看到,扫描完成后,我打开一个新活动,其中包含结果以进行确认:

private void showConfirmDialog(){
                    Intent confirmIntent = new Intent(QrCodeActivity.this, QrCodeConfirmActivity.class);
                    confirmIntent.putExtra(Constants.QR_CODE_MESSAGE, message);
                    startActivity(confirmIntent);
                }

当我参加此活动时,当我关闭此活动时,我会返回空白活动。 我认为这个空白活动是自定义视觉的捕获活动:

  

integrator.setCaptureActivity(QrCodeCaptureActivity.class);

错误在哪里?

由于

2 个答案:

答案 0 :(得分:1)

你必须添加一个简单的东西:: 在::

之后添加一个新行
languageArray = result;

for (i = [languageArray count] - 1; i >= 0; i--)
{
    NSString *languageTitle = [languageArray objectAtIndex:i];
    NSLog(@"languageTitle %@", languageTitle);
}

因此,您的上一次QR码活动将不再可见。

答案 1 :(得分:0)

我发现了错误...... 我调用一个活动而不是直接调用方法

  

integrator.initiateScan();