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??

4

3 に答える 3

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.

于 2011-06-01T11:51:00.320 に答える
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.

于 2011-06-03T17:08:48.653 に答える
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 :-)
于 2011-06-15T06:19:49.283 に答える