ZXING库基本应用
我正在尝试
public Button.OnClickListener mScan = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
};
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
使用库来生成,因此不需要安装软件,我查看了它附带的应用程序,并将 CaptureActivity.java 添加到我的项目中,看看是否可以找到核心扫描循环 但它一直需要越来越多的文件(最终总共大约有 28 个),在我没有错误之后它仍然无法工作。
我不想做任何花哨的事情,只需单击按钮打开捕获布局,扫描代码,返回代码。
有一些关于如何解码本地文件的示例,但没有关于如何解码本地文件的实际扫描端以检测实际条形码的示例。
所以,我帮助的是嵌入扫描码
谢谢
I am trying to produce
public Button.OnClickListener mScan = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
};
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
Using the libraries therefore not needing to install the software, I have had a look at the application that comes with it, and added CaptureActivity.java to my project to see if I can locate the core scanning loop but it kept just requiring more and more files (ended up with about 28 in total) and after I had no errors it still didn't work.
I am not looking into doing anything fancy, just on a button click open the capture layout, scan a code, return the code.
There are a few examples on how to decode local files but not the actual scanning side of it to detect a actual barcode.
So, what I help with is embedding the scanning code
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你混淆了两件事。您拥有的代码显示您正在尝试通过 Intent 进行集成,在这种情况下,您的应用程序中根本不需要任何项目代码。
android/
中的源代码是一个完整的独立应用程序(Barcode Scanner),它不是为您复制而编写的(尽管 Apache 许可证允许这样做)。您正在做的事情不受支持、推荐或鼓励——通过 Intent 集成要容易得多。编写您自己的应用程序,也许可以从 Android 源代码中寻找灵感,并使用
core/
库进行扫描。核心扫描发生在DecodeThread
中。I think you're mixing up two things. The code you have shows you are trying to integrate via Intent, in which case you do not need any project code in your application at all.
The source in
android/
is a complete stand-alone app (Barcode Scanner) and it is not written for you to copy (although the Apache License permits it). What you are doing is not supported, recommended, or encouraged -- integrating via Intent is much easier.Write your own app, perhaps looking to the Android source code for inspiration, and that uses the
core/
library for scanning. The core scanning happens inDecodeThread
.