-1

我正在使用以下扫描条形码行。

private Camera mCamera;
    private CameraPreview mPreview;
    public static final int MEDIA_TYPE_IMAGE = 1;
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newmain);

        Button captureButton = (Button) findViewById(R.id.button_capture);

//      Create an instance of Camera
        mCamera = getCameraInstance();

//      Create our Preview view and set it as the content of our activity.
        mPreview = new CameraPreview(this, mCamera);
        FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
        preview.addView(mPreview);
        final PictureCallback mPicture = new PictureCallback() 
        {
            public void onPictureTaken(byte[] data, Camera camera)
            {
                Intent intent = new Intent("http://zxing.appspot.com/scan");
//              Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
                startActivityForResult(intent, 0); 
            }
        };

            captureButton.setOnClickListener(new View.OnClickListener() 
            {
                public void onClick(View v) 
                {
                    Intent intent = new Intent("http://zxing.appspot.com/scan");
//                  Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
                    startActivityForResult(intent, 0); 

                    // get an image from the camera   
//                    System.out.println("Photo Taking!");
//                    mCamera.takePicture(null, null, mPicture);
                }
            });
    }

然后我使用以下方法将意图传递给 zxing sdk ..

public void onActivityResult(int requestCode, int resultCode, Intent intent) 
      {
          if (requestCode == 0)
          {
              TextView tvStatus=(TextView)findViewById(R.id.tvStatus);
              TextView tvResult=(TextView)findViewById(R.id.tvResult);
              if (resultCode == RESULT_OK) 
              {
                  String contents = intent.getStringExtra("SCAN_RESULT");
                  String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
                  tvStatus.setText(intent.getStringExtra(format));
                  tvResult.setText(intent.getStringExtra(contents));
                  Toast.makeText(getApplicationContext(), "Content:" + contents + " Format:" + format , Toast.LENGTH_LONG).show();
              }
              else if (resultCode == RESULT_CANCELED) 
              {
                  tvStatus.setText("Press a button to start a scan.");
                  tvResult.setText("Scan cancelled.");
              }
          }
      }

但是我无法将相机焦点放在条形码线上。如果我能就如何将相机聚焦在条形码线上得到一些帮助,我将不胜感激,这样我就可以将意图传递给 zxing sdk 。另外,对一些 Android 的评论sdk 扫描条形码行将不胜感激.. 提前谢谢..

4

1 回答 1

2

为什么要拍照发给zxing?您可以直接要求Zxing App打开相机并读取条形码。在这里查看我的答案。

于 2012-08-27T09:52:50.557 回答