Search code examples
androidandroid-studioandroid-intentbarcodezxing

How can I get the barcode scan ID in intent URL?


I want to scan a barcode ID and send it to the Google search engine but I have an issue.

When I scan, it will open this URL without getting the ID: https://www.google.com.pk/search?hl=en&q=scanContent +

I want it like this: https://www.google.com.pk/search?hl=en&q=12345 <-- (barcode ID)

How can I do this?

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (scanningResult != null) {
            if (scanningResult.getContents() != null) {
                scanContent = scanningResult.getContents().toString();
                scanFormat = scanningResult.getFormatName().toString();
            }

            Toast.makeText(this, scanContent + "   type:" + scanFormat, Toast.LENGTH_SHORT).show();

            textView.setText(scanContent + "    type:" + scanFormat);

            Intent browserIntent=new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com.pk/search?hl=en&q=scanContent + "));
            startActivity(browserIntent);

        } else {
            Toast.makeText(this, "Nothing scanned", Toast.LENGTH_SHORT).show();
        }
    }
}

Solution

  • dont put
    Intent browserIntent=newIntent(Intent.ACTION_VIEW,Uri.parse("https://www.google.com.pk/search?hl=en&q=scanContent + ")); startActivity(browserIntent);