我创建了一个条形码扫描仪,通过意图调用zxing条形码扫描仪。它检索结果代码和scan_result_format。如何从zxing条形码扫描仪中检索类型(如文本或产品)。我还想检索名称,价格等产品信息。我搜索并找到了解决方案,但这非常令人困惑。
这是我的代码。:
public void onClick(View arg0)
{
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
switch(arg0.getId()){
case R.id.butQR:
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
break;
case R.id.butProd:
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
break;
case R.id.butOther:
intent.putExtra("SCAN_FORMATS", "CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF,CODABAR");
break;
}
startActivityForResult(intent, 0); //Barcode Scanner to scan for us
}
}
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)
{
Intent intent1=new Intent(getApplicationContext(), Display.class);
intent1.putExtra("result_format", intent.getStringExtra("SCAN_RESULT_FORMAT"));
intent1.putExtra("result", intent.getStringExtra("SCAN_RESULT"));
startActivity(intent1);
}
else if (resultCode == RESULT_CANCELED)
{
tvStatus.setText("Press a button to start a scan.");
tvResult.setText("Scan cancelled.");
}
}