我正在创建一个使用 Android 上的 ZBar SDK 来扫描书籍并获取其 ISBN 的应用程序。我已经让一切都在身体方面发挥作用。您按下一个按钮,扫描仪窗口会弹出并扫描条形码。
当应用程序从扫描仪获取 ISBN 时,问题就出现了,似乎扫描仪读取条形码不正确,或者我没有提取正确的数据。有谁知道如何解决这个问题?谢谢。以下是相关代码,以及一些屏幕
@Override
public void onClick(View v)
{
//TODO add functionallity
if(v.getId() == R.id.ScanButton)
{
Intent intent = new Intent(this, ZBarScannerActivity.class);
intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.ISBN10, Symbol.ISBN13, Symbol.EAN8, Symbol.EAN13 });
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == RESULT_OK)
{
// Scan result is available by making a call to data.getStringExtra(ZBarConstants.SCAN_RESULT)
// Type of the scan result is available by making a call to data.getStringExtra(ZBarConstants.SCAN_RESULT_TYPE)
contentText.setText("ISBN: " + data.getStringExtra(ZBarConstants.SCAN_RESULT));
Toast.makeText(this, "Scan Result = " + data.getStringExtra(ZBarConstants.SCAN_RESULT), Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Scan Result Type = " + data.getStringExtra(ZBarConstants.SCAN_RESULT_TYPE), Toast.LENGTH_SHORT).show();
// The value of type indicates one of the symbols listed in Advanced Options below.
}
else if(resultCode == RESULT_CANCELED)
{
Toast.makeText(this, "Scanning Cancelled", Toast.LENGTH_SHORT).show();
}
}