0

我正在研究条形码扫描仪。当我单击扫描按钮时,出现以下异常。

07-05 16:15:50.328: E/AndroidRuntime(301): android.content.ActivityNotFoundException: 没有找到处理 Intent { act=com.google.zxing.client.android.SCAN (has extras) }

这是我的代码:

    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

}

}

我在清单文件中注册了 captureActivity。

4

2 回答 2

1

我认为你应该遵循这个

于 2012-07-05T10:56:40.290 回答
-1

如果您正在与 Zxing 集成,请确保您的 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>

您还需要将此发送到调用意图:

intent.setPackage(yourpackagestring);
于 2012-07-05T10:53:12.507 回答