在 Android 应用程序中单击按钮调用条形码扫描仪

发布于 2024-10-31 11:18:05 字数 189 浏览 5 评论 0原文

我已经下载了 zxing 1.6,并且能够通过它成功运行独立的条形码扫描仪。现在这个扫描仪位于另一个项目和(CaptureActivity)中,我有我的应用程序的不同项目,名为 MyProj ,我所有的 想要做的是单击我的项目中的按钮,在另一个项目中调用 CaptureActivity,如何将整个项目导入到我的项目中,或者我该怎么做才能使其正常工作。 提前致谢

I have downloaded the zxing 1.6 and was able to successfully run a standalone barcode scanner through it. Now this scanner is in another project and (the CaptureActivity) and I have my app's different project called MyProj , all I
want to do is on click of button in my project call CaptureActivity in another project , how do I import that entire project in my project or what do I do it get this working.
Thanking in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南笙 2024-11-07 11:18:05

我认为“复制”条形码扫描仪并将其包含在您的应用程序中可能会使您的项目超载。您当然应该使用扫描仪中的 Intent:

从此处:http://code.google。 com/p/zxing/wiki/ScanningViaIntent

如果您的 Android 设备上安装了条码扫描仪,您只需向其发送 Intent,就可以让它为您扫描并返回结果。例如,您可以连接一个按钮来扫描 QR 码,如下所示:

public Button.OnClickListener mScan = new Button.OnClickListener() {
    public void onClick(View v) {
        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);
    }
};

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
        }
    }
}

有关更多选项,例如扫描产品条形码,或要求条形码扫描仪为您编码并显示条形码,请参阅此源文件:

http://code. google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/Intents.java

以下是我们的测试应用程序中的一些源代码,展示了如何使用它们:

http ://code.google.com/p/zxing/source/browse/trunk/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java

IntentIntegrator

我们还开始创建一个小型库封装了上面一些细节的类。请参阅 IntentIntegrator,了解可能更简单的集成方法。特别是,这将处理尚未安装条形码扫描仪的情况。

http://code.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java

通过网址
从 Barcode Scanner v2.6 开始,您还可以从浏览器中的 URL 启动该应用程序。只需创建一个指向 http://zxing.appspot.com/scan 的超链接,条码扫描仪就会启动来处理它。用户还可以选择始终自动打开条形码扫描仪。

注意:此 URL 并不意味着在浏览器中提供实际的网页,它只是启动本机应用程序的挂钩。

已知问题
用户 jamesikanos 报告以下“陷阱”:

使用 launchMode“singleInstance”创建 TabHost 活动
使用“开始扫描”按钮创建一个子活动(使用此按钮中的 IntentIntegrator 启动 zxing)
您的子活动中的 onActivityResult 将立即返回“已取消”
onActivityResult 随后不会被调用

I think that "copying" Barcode Scanner and include it in your app might be overloading your projects. You should certainly use the Intent from the Scanner:

From here: http://code.google.com/p/zxing/wiki/ScanningViaIntent

If the Barcode Scanner is installed on your Android device, you can have it scan for you and return the result, just by sending it an Intent. For example, you can hook up a button to scan a QR code like this:

public Button.OnClickListener mScan = new Button.OnClickListener() {
    public void onClick(View v) {
        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);
    }
};

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
        }
    }
}

For more options, like scanning a product barcode, or asking Barcode Scanner to encode and display a barcode for you, see this source file:

http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/Intents.java

And here's some source from our test app which shows how to use them:

http://code.google.com/p/zxing/source/browse/trunk/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java

IntentIntegrator

We have also begun creating a small library of classes that encapsulate some of the details above. See IntentIntegrator for a possibly easier way to integrate. In particular this will handle the case where Barcode Scanner is not yet installed.

http://code.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java

Via URL
As of Barcode Scanner v2.6, you can also launch the app from a URL in the Browser. Simple create a hyperlink to http://zxing.appspot.com/scan and Barcode Scanner will offer to launch to handle it. Users can also choose to always have Barcode Scanner open automatically.

NOTE: This URL is not meant to serve an actual web page in a browser, it's just a hook to launch a native app.

Known Issues
User jamesikanos reports the following 'gotcha':

Create a TabHost activity with launchMode "singleInstance"
Create a child activity with a "Start scan" button (launch zxing using the IntentIntegrator from this button)
onActivityResult in your child activity will return immediately as "cancelled"
onActivityResult is never called subsequently

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文