2012-08-27 26 views
-1

我正在使用以下掃描條碼線。對焦和掃描來自android相機的條碼線

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); 
       } 
      }); 
    } 

然後我用下面的方法來傳遞意圖斑馬線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掃描條形碼行的評論將不勝感激。 Thanx提前..

回答

1

爲什麼你想拍照並將其發送給zxing?您可以直接詢問Zxing應用程序打開相機並閱讀條形碼。看到我的回答here

+0

是的,幾乎所有這一切都沒有必要。正確的方法是大約10行代碼... http://code.google.com/p/zxing/wiki/ScanningViaIntent –