如何在 Java、Android 上从 ZXing 源执行条形码扫描仪?

发布于 2024-12-25 00:25:40 字数 159 浏览 3 评论 0原文

我刚刚使用条形码扫描仪(ZXing 1.7)提出了申请。用户不在他的手机上使用条形码扫描仪,因此我无法将外部条形码扫描仪添加到我的应用程序中。我已将 ZXing 源添加到我的项目中,但我不知道如何在没有意图的情况下执行它。请帮我。

更新:或者如何使外部条形码扫描仪自动随我的应用程序安装?

I have just made application using BarCode scanner (ZXing 1.7). User doesn't use bar code scanner on his phone, therefore I can't add external Bar Code scanner into my application. I have added ZXing sources for into my project, but I don't know how I can execute it without intents. Please, help me.

Update: or how can I make that external bar code scanner will be installed automatically with my application?

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

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

发布评论

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

评论(3

尹雨沫 2025-01-01 00:25:40

您无法安装要自动安装的外部条码扫描仪。您可以做的是检查它是否已安装,如果没有显示一个对话框,询问用户是否要安装它(这会将用户带到应用程序市场链接)。

如果你想避免这种情况,你可以直接集成ZXing库,但这需要更多的工作。条形码扫描仪应用程序是开源的,因此您可以从那里了解如何操作。

You can't install the external barcode scanner to be installed automatically. What you could do is to check if it is installed, and if not show a dialog asking the user wether they want to install it (this will take the user to the app market link).

If you want to avoid this, you can integrate directly the ZXing library but it requires more work. The barcode scanner app is open source so you can see how to do it from there.

一曲琵琶半遮面シ 2025-01-01 00:25:40

如果手机中安装了zxing条码扫描器,则非常简单:

Intent intent = new Intent(
                                "com.google.zxing.client.android.SCAN");
                        intent.putExtra("SCAN_MODE", "PRODUCT_MODE");//for Qr code, its "QR_CODE_MODE" instead of "PRODUCT_MODE"
                        intent.putExtra("SAVE_HISTORY", false);//this stops saving ur barcode in barcode scanner app's history
                        startActivityForResult(intent, 0);

OnActivityResult中:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                    String contents = 

data.getStringExtra("SCAN_RESULT"); //this is the result
    }
else if (resultCode == RESULT_CANCELED) {

         // Handle cancel

}

如果未安装:您可以将此代码放在try-catch块中并捕获异常,您可以这样做:

Uri marketUri = Uri
                                .parse("market://details?id=com.google.zxing.client.android");
                        Intent marketIntent = new Intent(Intent.ACTION_VIEW,
                                marketUri);
                        startActivity(marketIntent);

因此,它将应用程序重定向到 Android 市场,并且如果安装了条形码扫描仪,您的应用程序将继续运行一次。

如果你不想在你的应用程序中使用其他应用程序,你必须下载 zxing 库并尝试使用 core.jar 文件中的类(它是使用 apache ant 创建的)。请按照本教程执行此操作:http://code.google.com/p/zxing/wiki/GettingStarted

If the zxing barcode scanner is installed in the mobile, its very easy:

Intent intent = new Intent(
                                "com.google.zxing.client.android.SCAN");
                        intent.putExtra("SCAN_MODE", "PRODUCT_MODE");//for Qr code, its "QR_CODE_MODE" instead of "PRODUCT_MODE"
                        intent.putExtra("SAVE_HISTORY", false);//this stops saving ur barcode in barcode scanner app's history
                        startActivityForResult(intent, 0);

and in OnActivityResult:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                    String contents = 

data.getStringExtra("SCAN_RESULT"); //this is the result
    }
else if (resultCode == RESULT_CANCELED) {

         // Handle cancel

}

If its not installed: u can put this code in try-catch block and catching the exception, u can do this:

Uri marketUri = Uri
                                .parse("market://details?id=com.google.zxing.client.android");
                        Intent marketIntent = new Intent(Intent.ACTION_VIEW,
                                marketUri);
                        startActivity(marketIntent);

So it redirects the app to android market and ur app continues running once if the barcode scanner is installed.

If u dont want to use the other app in ur app, U have to download zxing library and try using the classes from core.jar file(it is created using apache ant). Follow this tutorial to do that: http://code.google.com/p/zxing/wiki/GettingStarted

情独悲 2025-01-01 00:25:40

只需使用提供的基于 Intent 的集成代码即可。这很容易。它将把用户发送到市场来下载应用程序。这比尝试自动安装要好得多,原因至少有三个。首先,我认为用户不希望应用程序安装其他应用程序,并且可能不喜欢它。其次,只有当用户将设备设置为允许来自外部市场的第三方应用程序时,它才可能起作用。最后,您将安装一个可能旧的版本。

Just use the provided Intent-based integration code. It's very easy. It will send the user to Market to download the app. This is much better than trying to automatically install it for at least three reasons. First, I do not think users expect apps to install other apps and probably don't like it. Second it will only possibly work if the user has set the device to allow third-party apps from outside Market. Finally, you will be installing a potentially old version.

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