Question

My idea is when i scan a definite QR code, the app open a new Activity What kind of command I need?

The Activity:

 @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){
            {

    }

    }
  }
}
Était-ce utile?

La solution

To call a new activity when a QRCode has been scanned, you must use an intent in the onActivityResult:

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);
        }

    }

If you want to parse or validate the scaned QRcode first, you can do the following:

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

Then you can compare contents with your expected string:

if(contents.equals("CorrectScan")) { .......
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top