【问题标题】:Android barcode reading安卓条码读取
【发布时间】:2012-06-11 19:36:00
【问题描述】:

我正在开发一个条码扫描应用程序,并使用 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 消息。

我做错了什么?

【问题讨论】:

    标签: android zxing barcode-scanner


    【解决方案1】:

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

    【讨论】:

    • 谢谢! IntentIntegrator 已生成扫描结果
    • @Niek 因为他已经发现该工具可以正确使用IntentIntegrator,但只在中途使用它。使用IntentIntegrator 是正确的方法。使用它显然修复了它。这正是我所说的。那么你的问题/反对意见是什么?
    猜你喜欢
    • 2011-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多