0

I have posted a question before and got response regarding Barcode scanning in ZXing.

Currently i have run the barcode scanner app code, that is given in the source(/android/) using this post

My objective is to scan a barcode in my app. Since zxing is open source as told by the authors, i need to customize the scanner app raw code in my app. I found many files like WifiActivity and all. I dont know whether all the files are required to scan a barcode.

Now i want to extract the necessary and required files to decode using the camera captured image. Is it possible to extract the parts? If yes, can anyone help me in doing this by referring any links or steps. Thanks for all your useful posts and great responses. Sorry for my bad english.

Community
  • 1
  • 1
lingesh
  • 1
  • 2

2 Answers2

1

what exactly are you trying to achieve? Do you want to edit and enhance the ZXing Source/App or want to use this library in your App for scanning.

For scanning you could invoke the activity for the scan result like following:

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
try {
startActivityForResult(intent, REQUEST_CODE);
} catch (ActivityNotFoundException e) {
    //Do something here
}

After scan u will receive the result in onActivityResult method:

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
}
Ash
  • 1,391
  • 15
  • 20
  • Thanks a lot @Ash for the quick reply. What i am trying to achieve is, as u mentioned i need to use the zxing scanner library files and am not enhancing the existing. In our app, barcode/QRcode scanning is also one of the feature. My question is, do we need to have all the files like EncodeActivity, ShareActivity, AppPickerActivity and so on. I am having a doubt that these activities are not connected with barcode scanning part and the **\android\res\** files also. Please help me in extracting the required library files to implement the scan module only. And Thanks for helping :) – lingesh Jul 28 '11 at 07:46
  • There are various ways to invoke Zxing Capture Activity: 1. Invoke the Zxing if user already has on his phone else install the Zxing from the Android Market 2. Make the Zxing part of your project!! (You can copy the ZXing source code right into your project's src directory and define capture activity intent in your manifest file) - Just In the Zxing lib - A folder "android" along with the core Lib for linking the source will work!! If i just want scanning, I would not bother about touching/modifying the existing code – Ash Jul 28 '11 at 09:08
  • Building the Zxing code on eclipse: http://www.falatic.com/index.php/12/building-zxing-for-android-part-3-using-eclipse – Ash Jul 28 '11 at 09:12
  • thanks again @Ash. i went through the link u gave. I can able to build the /android/ src and can compile and run. And i also read one post http://stackoverflow.com/questions/5969679/yet-another-question-about-embedding-zxing-in-android-app. In this, they discussed about the strip down of existing classes. This is what i wanted to add them as library. As mentioned in that post, can you please comment and help me in this? Sorry for asking questions again and again... :( – lingesh Jul 28 '11 at 11:17
  • @lingesh I m not sure, But 1 way u could do is -put the logs in constructors and see what all objects are called for scanning/(your costomized scanning)... – Ash Jul 28 '11 at 12:45
  • I made code for barcode generate and scan barcode. You can follow this to get the Step By Step Code. https://stackoverflow.com/a/58742737/11613683 – Pramesh Bhalala Nov 07 '19 at 09:28
0

I did something similar to this, but I only wanted the QR generation part of the zxing project. So I found the relevant call (maybe something like Bitmap b = zx.genQRCode() or whatever) and copied that java file into my project.

Compile and BAM - you get a ton of compile errors. At the point you just start copying other referenced files into your project until you don't get any more compile errors.

Don't forget to include proper attribution in your app - see this FAQ.

Josh
  • 10,618
  • 2
  • 32
  • 36