集成ZXing到应用程序 [英] Integrating ZXing into application

查看:169
本文介绍了集成ZXing到应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是很多现有的类似问题重复。但我看过几乎所有的讨论,并没有帮助。我的目标是嵌入zxing库到我的应用程序,并扫描QR codeS,而无需引用外部应用程序。我针对当前平台的是Android 4.2。

This may seem to be a duplicate of many existing similar questions. But I've read almost all discussions and none is helping. My goal is to embed zxing library into my application, and scan QRCodes without needing to reference external application. Current platform I'm targeting is android 4.2.

我一遍又一遍地完成以下步骤:

I've completed the following steps over and over :


  1. 下载zxing-2.3.0源

  2. 使用Maven编译zxing-2.3.0 /核心 - 拿到核心2.3.0.jar

  3. 创建一个新的项目与zxing-2.3.0 /安卓/补充核心2.3.0.jar到/ libs文件夹,更改switch语句来如果{}从句,去掉最后从CaptureActivity,标记为图书馆,打造= captureactivity.jar

  4. 返回到我原来的应用程序。新增核心2.3.0.jar和captureactivity.jar我/ libs文件夹中。

  5. 还增加了库/ captureactivity.jar为下属性/ Java构建路径/库/添加JARS / ..(这没什么区别不过,即使我不我会得到同样的错误)

  6. 我创建扩展CaptureActivity一类叫做ScannerActivity(下面详细介绍)

当我跑我终于得到了异常之前看到很多来自dalvikvm资源解决问题的应用程序。据我了解/测试zxing库无法访问是本地的资源文件或静态变量时,作为一个库编译。这将最终炸毁了的NoClassDefFoundError试图找到RelativeLayout的为CaptureActivity。

When I run the application I see a lot of resource resolve problems from dalvikvm before finally getting the exception. To my understanding/testing zxing library cannot access is local Resource files or static variables when compiled as a library. It'll finally blow up with a NoClassDefFoundError trying to locate the RelativeLayout for CaptureActivity.

下面是错误类型我得到的名单减少

Here is a reduced list of error types I'm getting.

01-04 23:30:37.851: W/dalvikvm(9804): VFY: unable to resolve static field 1711 (decode_succeeded) in Lcom/google/zxing/client/android/R$id;
01-04 23:30:37.851: D/dalvikvm(9804): VFY: replacing opcode 0x60 at 0x0011
01-04 23:30:37.851: W/dalvikvm(9804): VFY: unable to resolve static field 1761 (app_name) in Lcom/google/zxing/client/android/R$string;
01-04 23:30:37.851: D/dalvikvm(9804): VFY: replacing opcode 0x60 at 0x0005
..................(more of similar)
01-04 23:30:37.875: I/dalvikvm(9804): DexOpt: unable to optimize static field ref 0x0702 at 0x0e in Lcom/google/zxing/client/android CaptureActivity;.displayFrameworkBugMessageAndExit
01-04 23:30:37.875: I/dalvikvm(9804): DexOpt: unable to optimize static field ref 0x06eb at 0x17 in Lcom/google/zxing/client/android/CaptureActivity;.displayFrameworkBugMessageAndExit
..................(more of similar)
01-04 23:30:43.617: E/AndroidRuntime(9804): FATAL EXCEPTION: main
01-04 23:30:43.617: E/AndroidRuntime(9804): java.lang.NoClassDefFoundError: com.google.zxing.client.android.R$layout
01-04 23:30:43.617: E/AndroidRuntime(9804):     at com.google.zxing.client.android.CaptureActivity.onCreate(CaptureActivity.java:134)
..................(rest of exception stack)


package my.android.application;

import my.android.ordertaker.R;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.Toast;

import com.google.zxing.Result;
import com.google.zxing.client.android.CaptureActivity;

public class ScannerActivity extends CaptureActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scanner);
    }

    @Override
    public void handleDecode(Result rawResult, Bitmap barcode, float scaleFactor) {
        Toast.makeText(this.getApplicationContext(), "Scanned code " + rawResult.getText(), Toast.LENGTH_LONG);
    }
}

下面是AndroidManifest

Here is AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="my.android.ordertaker"
    android:versionCode="3"
    android:versionName="3.0" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- uses-permission android:name="android.permission.ACCESS_WIFI_STATE" / -->
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" />

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />
    <!-- android:theme="@style/AppTheme" -->
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/CustomTheme" >

        <activity
            android:name="my.android.application.ScannerActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- service android:name="com.commonsware.cwac.updater.UpdateService"/ -->
        <!-- receiver android:name="com.commonsware.cwac.updater.WakefulReceiver"/ -->

        <receiver android:name="my.android.io.NetworkStatusListener" >
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" >
                </action>
            </intent-filter>
        </receiver>
    </application>

</manifest>

还有什么我已经尝试:我已经打了zxing / Android源(captureactivity.jar)通过修改,试图删除直接值R.id引用(硬codeD),掏出一些类我自己的项目,改变了一些源访问公众等,我有一些成功的,我甚至还有摄像头的工作,但我不能在最后进行管理,范围只是太大处理,所以我又恢复。

What else I've tried : I've played with zxing /android source (captureactivity.jar) by modifying it, tried to remove R.id references with direct values (hard coded), pulled out some of the classes to my own project, changed some source accessors to public, etc, and I had some success with that, I even got the camera working, but I couldn't manage it at the end, the scope is just too big to handle, so I reverted back.

从我的经验,这个问题似乎来自不能够引用它的内部资源生成的库(captureactivity.jar)来产生的,但我可能是错的。我的问题似乎比技术更重要。我在做什么错了?

From my experience the problem seems to arise from generated library(captureactivity.jar) not being able to reference it's internal resources, but i might be wrong. My problem seems to be more fundamental than technical. What am I doing wrong?

推荐答案

开始与制作斑马线项目作为库项目来处理与资源问题。正如@SeanOwen指出的,你需要,如果你打算用适当的归属一起分发它改变了用户界面。

Start with making the ZXing project as a library project to deal with the resource issue. As @SeanOwen noted you will need to change the UI if you intend to distributed it along with appropriate attribution.

这篇关于集成ZXing到应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆