Android条形码阅读

时间:2012-06-11 19:36:00

标签: android zxing barcode-scanner

我正在开发条形码扫描应用程序并使用Zxing作为条形码扫描仪。我的应用程序向Zxing发送了一个意图,它启动并允许我扫描条形码但是......我无法获得任何数据。我没有将条形码编号返回到我的应用程序,因此我可以在我的代码中使用它们。

以下是我的代码:

public class ScaningActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);        

Intent scanIntent = new Intent("com.google.zxing.client.android.SCAN");
    scanIntent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
    startActivityForResult(scanIntent, 0);

}//close onCreate
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
      IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
      if (scanResult != null) {
        // handle scan result
        Log.e("DATA", "TESTING SCAN RESULT : " + scanResult.toString());
      }else{
          Log.d("DATA", "NO SCAN RESULTS : ");// + scanResult.getFormatName());//scanResult.getContents());
      }
      // else continue with any other code you need in the method
      Log.i("DATA", "Continuing after scan result");
      Log.d("DATA", "requestCode : " + requestCode);
      Log.d("DATA", "resultCode : " + resultCode);
      Log.d("DATA", "intent : " + intent);
    }
}//close ScaningActivity

onActivityResult函数中,我收到 NO SCAN RESULTS 消息。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

不要试图自己这样做,因为你做错了。特别是您没有正确发送Intent。另请使用IntentIntegrator