0

I have used the same way of Zxing Intent to open scanner from my application. But my application just opens scanner and does nothing. Also, I am getting some FileNotfoundException.

Do I have to add any permission in manifest?

This is my class where I use Intent:

public class BarCodes extends Activity {

   /** Called when the activity is first created. */
   @Override public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      Button ok;

      ok=(Button) findViewById(R.id.b1);
      ok.setOnClickListener(new View.OnClickListener() {  

         @Override public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            intent.setPackage("com.google.zxing.client.android");
            intent.putExtra("SCAN_MODE","QR_CODE_MODE");
            startActivityForResult(intent, 0);
         }

      });
      System.out.println("SSSSSSSSSSSSS");
   }

   public void onActivityResult(int requestCode, int resultCode, Intent intent) {
      if (requestCode == 0) {   
          if (resultCode == RESULT_OK) {
              String contents = intent.getStringExtra("SCAN_RESULT");
              System.out.println("contentsssssssssssssssssssssss" + contents);
              String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
              // Handle successful scan
          } else if (resultCode == RESULT_CANCELED) {
              // Handle cancel
          }
       }
    }
}

Also LogCat is here:

java.lang.RunTimeException:Unable to instantiate activity componentInfo{com.pkg.BarCode...}  
caused by : java.lang.classNotFoundException:com.pkg.Scan in loader dalvik.System   Loader…  

What might be the problem??

Dori
  • 915
  • 1
  • 12
  • 20
Smitha
  • 6,110
  • 24
  • 90
  • 161

3 Answers3

0

This question is answered in more detail here and here. As to why you are getting the FileNotFoundException you'd have to provide more detail, such as the code for which you are invoking the Zxing intent as well as the logcat stack trace.

Community
  • 1
  • 1
jengelsma
  • 8,192
  • 4
  • 21
  • 21
  • Intent intent = new Intent("com.google.zxing.client.android.SCAN"); I am getting error with this one. As it is an action(SCAN) in log it still says SCAN activity is missing. – Smitha Jun 13 '11 at 10:20
  • [link](http://code.google.com/p/zxing/wiki/GettingStarted) could anybody let me know how to edit this build properties?? – Smitha Jun 13 '11 at 11:15
  • You will either have to have the ZXing app installed on the device or copy the com.google.zxing.client.* source packages into your own project's source directory. If you take the latter approach, be sure you add the activity to your manifest file, e.g. Hope this helps. – jengelsma Jun 15 '11 at 19:26
0

Your error is nothing to do with the project. Android is saying it is unable to find your class, com.pkg.Scan. You'll have to fix your project setup.

However I'd further suggest that you not try to write your own code, but use the code provided by the project to integrate via Intent.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
0

Steps:

  1. Install Apache Ant (http://www.youtube.com/watch?v=XJmndRfb1TU , this video will help you to do that) and also refer http://ant.apache.org/ for more info and download ant
  2. Download the ZXing source from ZXing homepage and extract it (For More info :http://code.google.com/p/zxing/source/browse/trunk/android/)
  3. With the use of Windows Commandline (Run->CMD) navigate to the extracted directory
  4. Type 'ant -f core/build.xml' or 'ant -f android/build.xml'
  5. Enter Eclipse -> new Android Project
  6. Right-click project folder -> Properties -> Java Build Path -> Library -> Add External JARs
  7. If the Barcode Scanner is installed on your Android device, you can have it scan for you and return the result, just by sending it an Intent. For example, you can hook up a button to scan a QR code in this way
  8. It will have the product code Stored in the String value 'contents'
    Have fun with BarCode by implementing it in your own way :-)
Smitha
  • 6,110
  • 24
  • 90
  • 161