Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9299507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:34:37+00:00 2026-06-18T22:34:37+00:00

I used this answer to create a standalone Android library project that has the

  • 0

I used this answer to create a standalone Android library project that has the ZXing source code in it (ZXing v2.1). It compiles fine and if I run CaptureActivity, I can read a QR code as expected.

I have another Android project from which I want to pull in this library. I have set that library relationship up correctly.

The issue I am having is, how do I launch my local copy of the ZXing scanner via IntentIntegrator (mentioned here).

I tried modifying the IntentIntegrator.initiateScan() method to use my local copy of CaptureActivity, and that loads the QR scanner properly. However, once the QR code is scanned the QR information is displayed on-screen instead of sending the result back to my calling activity in onActivityResult.

How can I make it send the QR scan results to onActivityResult of my calling activity?

For reference, here is what I changed the IntentIntegrator.initiateScan() method to:

  public AlertDialog initiateScan(Activity act, Collection<String> desiredBarcodeFormats) {       

  //Hardcoding name of activity to call --> is this where I've gone wrong?
    Intent intentScan = new Intent(act, CaptureActivity.class);

    intentScan.addCategory(Intent.CATEGORY_DEFAULT);

    // check which types of codes to scan for
    if (desiredBarcodeFormats != null) {
      // set the desired barcode types
      StringBuilder joinedByComma = new StringBuilder();
      for (String format : desiredBarcodeFormats) {
        if (joinedByComma.length() > 0) {
          joinedByComma.append(',');
        }
        joinedByComma.append(format);
      }
      intentScan.putExtra("SCAN_FORMATS", joinedByComma.toString());
    }


//Commented this out because it didn't seem to find my class...

//    String targetAppPackage = findTargetAppPackage(intentScan);
//    if (targetAppPackage == null) {
//      return showDownloadDialog();
//    }
//    
//    
//    intentScan.setPackage(targetAppPackage);
    intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    attachMoreExtras(intentScan);
    startActivityForResult(intentScan, REQUEST_CODE);
    return null;
  }

And I’m initiating the scan like this:

IntentIntegrator integrator = new IntentIntegrator(getActivity());
integrator.initiateScan(getActivity());

I feel like I’m missing something easy here, any push in the right direction would be great.

SOLUTION

Here’s what ended up working. I still invoke it the same way with:

IntentIntegrator integrator = new IntentIntegrator(getActivity());
integrator.initiateScan(getActivity());

But the initiateScan method now looks like this:

  public AlertDialog initiateScan(Activity act, Collection<String> desiredBarcodeFormats) 
  {

    Intent intentScan = new Intent(BS_PACKAGE + ".SCAN");

    intentScan.addCategory(Intent.CATEGORY_DEFAULT);

    // check which types of codes to scan for
    if (desiredBarcodeFormats != null) {
      // set the desired barcode types
      StringBuilder joinedByComma = new StringBuilder();
      for (String format : desiredBarcodeFormats) {
        if (joinedByComma.length() > 0) {
          joinedByComma.append(',');
        }
        joinedByComma.append(format);
      }
      intentScan.putExtra("SCAN_FORMATS", joinedByComma.toString());
    }

    //THIS WAS THE KEY
    setSingleTargetApplication(act.getPackageName());

    String targetAppPackage = findTargetAppPackage(intentScan);
    if (targetAppPackage == null) {
      return showDownloadDialog();
    }

    intentScan.setPackage(targetAppPackage);
    intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    attachMoreExtras(intentScan);
    act.startActivityForResult(intentScan, REQUEST_CODE);
    return null;
  }

Important things are make sure that BS_PACKAGE points to the CaptureActivity package, that you call “act.startActivityForResult…” instead of just “startActivityForResult…” and that you call setSingleTargetApplication with the package name of the application that will be calling the scanner.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T22:34:38+00:00Added an answer on June 18, 2026 at 10:34 pm

    Try to change the line startActivityForResult(intentScan, REQUEST_CODE);

    to act.startActivityForResult(intentScan, REQUEST_CODE);

    You do not need to comment the code that contains findTargetAppPackage, just set your target application’s package by calling setSingleTargetApplication() (if you are the only application using this library)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Django project, that has a Address model. This is used in
i used this code: List<string> lists=new List<string>(apple,orange,banana,apple,mang0,orange); string names; names=lists.Distinct() is that correct?
This answer explains how to create test cases dynamically. The answer's code: class Tests(unittest.TestCase):
Using this answer as a guide, I set out to create a select_year that
I was reading this answer and trying to copy the method used there, but
I used this MSDN example to construct my console host app: http://msdn.microsoft.com/en-us/library/ms731758.aspx It works
I used this tutorial to create a basic Javascript function for implementing change during
I used this link to create a SHA1 hash for any data using C++.
I used this code to draw a line in a panel. private bool isMoving
I am developing an Eclipse wizard that will be used for creating a project.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.