ZXing QR Code Scanner应该打开一个新的活动

时间:2014-02-05 16:14:16

标签: android qr-code zxing

我的想法是,当我扫描一个明确的二维码时,该应用程序会打开一个新的活动 我需要什么样的命令?

活动:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.c_wall);





    }
    public void onClick (View view){
        IntentIntegrator integrator =new IntentIntegrator(this);
        integrator.initiateScan();
}
    public void onActivityResult(int requestCode, int resultCode, Intent intent){
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
        if (scanResult != null){
            {

    }

    }
  }
}

1 个答案:

答案 0 :(得分:0)

要在扫描QRCode时调用新活动,您必须在onActivityResult中使用intent:

public void onActivityResult(int requestCode, int resultCode, Intent intent){
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
        if (scanResult != null){
               Intent newactivity = new Intent(ThisClass.this, NextActivity.class);
               startActivity(newactivity);
        }

    }

如果您想首先解析或验证扫描的QRcode,您可以执行以下操作:

String contents = intent.getStringExtra("SCAN_RESULT");

然后,您可以将内容与预期的字符串进行比较:

if(contents.equals("CorrectScan")) { .......