2014-02-14 85 views
0

我是Android新手。我正在嘗試使用zbar讀取條形碼。我使用DushyanthMaguluru/ZBarScanner/ZBarScannerDemo.在Android的Zbar中沒有檢測到條形碼條碼

測試問題是應用程序正在打開,當我單擊掃描按鈕時,它只是打開相機,檢測條形碼的紅線不會到來。我不知道我哪裏出錯了。

和我MAinactivity.Java代碼

package com.example.zbartest; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.content.Intent; 
import android.content.pm.PackageManager; 
import android.text.TextUtils; 
import android.view.View; 
import android.widget.Toast; 
import android.widget.TextView; 
import com.dm.zbar.android.scanner.ZBarConstants; 
import com.dm.zbar.android.scanner.ZBarScannerActivity; 
import net.sourceforge.zbar.Symbol; 
public class MainActivity extends Activity { 

private static final int ZBAR_SCANNER_REQUEST = 0; 
private static final int ZBAR_QR_SCANNER_REQUEST = 1; 

private TextView formatTxt, contentTxt; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    formatTxt = (TextView)findViewById(R.id.scan_format); 
    contentTxt = (TextView)findViewById(R.id.scan_content); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

public void launchScanner(View v) { 
    if (isCameraAvailable()) { 
     Intent intent = new Intent(this, ZBarScannerActivity.class); 
     startActivityForResult(intent, ZBAR_SCANNER_REQUEST); 
    } else { 
     Toast.makeText(this, "Rear Facing Camera Unavailable", Toast.LENGTH_SHORT).show(); 
    } 
} 

public void launchQRScanner(View v) { 
    if (isCameraAvailable()) { 
     Intent intent = new Intent(this, ZBarScannerActivity.class); 
     intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE}); 
     startActivityForResult(intent, ZBAR_SCANNER_REQUEST); 
    } else { 
     Toast.makeText(this, "Rear Facing Camera Unavailable", Toast.LENGTH_SHORT).show(); 
    } 
} 

public boolean isCameraAvailable() { 
    PackageManager pm = getPackageManager(); 
    return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    switch (requestCode) { 
     case ZBAR_SCANNER_REQUEST: 
     case ZBAR_QR_SCANNER_REQUEST: 
      if (resultCode == RESULT_OK) { 
       Toast.makeText(this, "Scan Result = " + data.getStringExtra(ZBarConstants.SCAN_RESULT), Toast.LENGTH_SHORT).show();       
       String scanFormat = data.getStringExtra("SCAN_RESULT"); 
       String scanContent = data.getStringExtra("SCAN_RESULT_FORMAT"); 
       formatTxt.setText("FORMAT: " + scanFormat); 
       contentTxt.setText("CONTENT: " + scanContent); 
      } else if(resultCode == RESULT_CANCELED && data != null) { 
       String error = data.getStringExtra(ZBarConstants.ERROR_INFO); 
       if(!TextUtils.isEmpty(error)) { 
        Toast.makeText(this, error, Toast.LENGTH_SHORT).show(); 
       } 
      } 
      break; 
    } 
} 
} 

我已經加入在我的項目的src文件夾中的ZbarScannerActivity,CameraPreview,ZbarConstatnts java文件,並添加了ZbarScannerlibrary文件到libs文件夾。 我剛從示例中複製了三個ZbarScannerActivity,CameraPreview,ZbarConstatnts文件並粘貼到我的項目中。

請幫忙

回答

0

也許你需要清理和重建項目。

並再試一次