我正在研究条形码扫描仪。当我单击扫描按钮时,出现以下异常。
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。