所以,我一直在尝试使用 Google Goggles Intent,这样我就可以将扫描仪用作 OCR 设备。我在我的活动中使用了以下代码:
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
//intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
Log.d("TAG", "start goggles!");
startActivityForResult(intent, 0);
至于我的 onActivityResult,它看起来像这样:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Log.d("TAG", "result back!"+contents);
Toast.makeText(getBaseContext(), contents, Toast.LENGTH_LONG).show();
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(getBaseContext(), "CANCELLED", Toast.LENGTH_LONG).show();
// TODO: Handle cancel
}
}
}
上面的代码成功启动了另一个应用程序,但无法带回结果,并且总是以 RESULT_CANCELLED resultCode 结束。(我正在使用后退按钮返回我的应用程序,我在这里做错了吗?)
任何帮助,将不胜感激。谢谢!