如何从条形码中检索产品 ID?
我使用了与 Zxing Intent 相同的方式从我的应用程序中打开扫描仪。但我的应用程序只是打开扫描仪,什么也不做。另外,我收到一些 FileNotfoundException。
我需要在清单中添加任何权限吗?
这是我使用 Intent 的课程:
public class BarCodes extends Activity {
/** Called when the activity is first created. */
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button ok;
ok=(Button) findViewById(R.id.b1);
ok.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE","QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
System.out.println("SSSSSSSSSSSSS");
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
System.out.println("contentsssssssssssssssssssssss" + contents);
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
}
LogCat 也在这里:
java.lang.RunTimeException:Unable to instantiate activity componentInfo{com.pkg.BarCode...}
caused by : java.lang.classNotFoundException:com.pkg.Scan in loader dalvik.System Loader…
可能是什么问题?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此处和此处。至于为什么会收到 FileNotFoundException,您必须提供更多详细信息,例如您调用 Zxing 意图的代码以及 logcat 堆栈跟踪。
This question is answered in more detail here and here. As to why you are getting the FileNotFoundException you'd have to provide more detail, such as the code for which you are invoking the Zxing intent as well as the logcat stack trace.
你的错误与项目无关。 Android 表示无法找到您的类
com.pkg.Scan
。您必须修复项目设置。不过,我进一步建议您不要尝试编写自己的代码,而是使用提供的代码由项目通过Intent进行集成。
Your error is nothing to do with the project. Android is saying it is unable to find your class,
com.pkg.Scan
. You'll have to fix your project setup.However I'd further suggest that you not try to write your own code, but use the code provided by the project to integrate via Intent.
步骤:
以您自己的方式实现 BarCode,享受 BarCode 的乐趣 :-)
Steps:
Have fun with BarCode by implementing it in your own way :-)