I want to Scan QR codes on button Click, problem is when I run code on my device Activity Result Intent variable always returns 0.
How do I know if the barcode reader work? I currently see yellow dots on the device’s screen.
Here is my code:
private OnClickListener scanner = new OnClickListener() {
public void onClick(View v) {
IntentIntegrator.initiateScan(BarCodeScannerActivity.this);
}
};
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
// handle scan result
String s = "http://www.google.com/search?q=";
s += scanResult.getContents();
Intent myIntent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(s));
startActivity(myIntent1);
}
Thanks
You have error in code
You should have
You are not overriding the
onActivityResultlikeonCreateoronStartRather you are writing onActivityResult like normal method which is most common mistake.
Also if you can mention
integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES);orintegrator.initiateScan(IntentIntegrator.PRODUCT_CODE_TYPES);it would be great.