zain
zain

Reputation: 11

Android Barcode Scanner Issue

I am working on Barcode Scanner. when i click on scan button, getting following exception.

07-05 16:15:50.328: E/AndroidRuntime(301): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN (has extras) }

Here is my code:

    getWindow().setFormat(PixelFormat.UNKNOWN);

    surfaceHolder = surfaceView.getHolder();
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    scan_btn.setOnClickListener( new View.OnClickListener() {

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

            startActivityForResult(scanIntent, 0);

               if(!previewing){
                     camera = Camera.open();
                     if (camera != null){
                      try {
                       camera.setPreviewDisplay(surfaceHolder);
                       camera.startPreview();
                       previewing = true;
                      } catch (IOException e) {
                       // TODO Auto-generated catch block
                       e.printStackTrace();
                      }
                     }
                    }

        }

    });
} 

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
               if (requestCode == 0) {
                  if (resultCode == RESULT_OK) {
                 String contents = intent.getStringExtra("SCAN_MODE");
                 String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
                 // Handle successful scan
                result_text.setText(intent.getStringExtra("SCAN_RESULT"));
                  } else if (resultCode == RESULT_CANCELED) {
                     // Handle cancel
                      result_text.setText("Scan cancelled.");
                  }
               }
            }           

@Override
public void surfaceCreated(SurfaceHolder paramSurfaceHolder) {
    // TODO Auto-generated method stub

}
@Override
public void surfaceChanged(SurfaceHolder paramSurfaceHolder, int paramInt1,
        int paramInt2, int paramInt3) {
    // TODO Auto-generated method stub

}
@Override
public void surfaceDestroyed(SurfaceHolder paramSurfaceHolder) {
    // TODO Auto-generated method stub

}

}

i have register captureActivity in manifest file.

Upvotes: 0

Views: 457

Answers (2)

Mohsin Naeem
Mohsin Naeem

Reputation: 12642

I think you should follow this.

Upvotes: 1

Suave Nti
Suave Nti

Reputation: 3757

If you are integrating with Zxing make sure you have this in your Manifest :

 <activity android:name="com.google.zxing.client.android.CaptureActivity"
 android:screenOrientation="landscape"
 android:configChanges="orientation|keyboardHidden"
 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
 android:windowSoftInputMode="stateAlwaysHidden">
 <intent-filter>
   <action android:name="com.google.zxing.client.android.SCAN"/>
  <category android:name="android.intent.category.DEFAULT"/>
 </intent-filter>

also you need to send this to the calling intent :

intent.setPackage(yourpackagestring);

Upvotes: -1

Related Questions