zxing扫描条形码后,如何搜索保存在原始资源文件夹中保存的文本文件中的条形码?这些需要分开进行吗?我觉得这是一项简单的任务。我让扫描仪工作得很完美我挂了如何将扫描结果与txt文件进行比较。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result != null) {
if (result.getContents() == null) {
Log.d("MainActivity", "cancelled");
Toast.makeText(this, "cancelled", Toast.LENGTH_LONG).show();
} else {
Log.d("MainActivity", "scanned");
Toast.makeText(this, "scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
Cursor c = db.getWordMatches(query, null);
}
try {
FileInputStream in = new FileInputStream(R.raw.upc);
int len = 0;
byte[] data1 = new byte[1024];
while (-1 != (len = in.read(data1))) {
if (new String(data1, 0, len).contains(result.getContents()))
//do something...
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}