zxing barcode类库使用

zxing:   http://code.google.com/p/zxing/

整合到自己项目中,步骤:

1:从官网下载最新的版本,我下载的是ZXing-2.1.zip

2:将zxing-2.1\android下的src、assets、res等文件整合到项目中

3:修改com.google.zxing.client.android.CaptureActivity类handleDecodeInternally函数

      修改函数实现为:   

      String strResult = resultHandler.getDisplayContents().toString();
      Intent data = new Intent();
      data.putExtra("SCAN_RESULT",strResult);
      setResult(RESULT_OK, data);
      finish();

4:页面A需要调用 CaptureActivity类进行barcode扫描

      声明命令:

    /*
     * 使用ZXing扫描
     */
    private static final int ZXING_SCAN = 3; 

     接收Result的实现

    @Override    
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {    
	super.onActivityResult(requestCode, resultCode, data);  
	//ZXING扫描
	if(requestCode == ZXING_SCAN){
	    if (resultCode == RESULT_OK) { 
	        String zxingresult = data.getStringExtra("SCAN_RESULT");
		Toast.makeText(this, zxingresult, Toast.LENGTH_SHORT).show();
            }else{	
	    }
	}
    } 

      发送扫描请求:

   Intent launchintent = new Intent(A页面.this,CaptureActivity.class);
   ActivityFMActivity.this.startActivityForResult(launchintent,ZXING_SCAN); 




    

你可能感兴趣的:(zxing barcode类库使用)