我会开始解释一切我都做,到底是什么问题的步骤。
I'll start explaining all the steps I have done and in the end what is the problem.
下载ZXing-2.2 https://$c$c.google.com/p/zxing/downloads/list 为Extrac所有zxing-2.2。 在下载和安装Apache Ant的http://www.youtube.com/watch?v=XJmndRfb1TU 通过使用命令行的Windows(运行 - > CMD)的定位到解压目录 在命令行窗口 - 输入'蚂蚁-f核心/ build.xml文件'preSS输入,让Apache的工作,它的魔力 Download ZXing-2.2 https://code.google.com/p/zxing/downloads/list Extrac all in zxing-2.2. Download and install Apache Ant http://www.youtube.com/watch?v=XJmndRfb1TU With the use of Windows Commandline (Run->CMD) navigate to the extracted directory In the commandline window - Type 'ant -f core/build.xml' press enter and let Apache work it's magic在这一刻像Integration直接ZXing库到我的Android应用程序
但Wooops,构建文件:核心 build.xml文件不存在生成失败OK。 6. 导入ZXing - 缺少核心/ build.xml文件
But Wooops, "Buildfile: corebuild.xml does not exists! Build failed. ok. 6. Importing ZXing - missing core/build.xml
现在是的,我有我的core.jar添加。
Now yes, i have my core.jar.
开启Android的工作室,文件 - >导入项目 - >选择/安卓/在/zxing-2.2/ - >创建一个从现有的资源项目 - >项目名称:andoid - >源文件......所有选中的下一步 - >库(不能做什么)下一步 - >模块(安卓选中)下一步 - > SDK 1.7下一步 - >完成使用项目打开 - >构建 - >重建项目
With Project Open -> Build -> Rebuild project
100错误 19警告
100 errors 19 warnings
文件 - >项目结构 - >库 - >添加 - >爪哇 - >我创建前,确定选择core.jar添加 - >库芯将被添加到所选择的模块。 (机器人)的确定 - >确定并在项目结构对话框
File -> project Structure -> Libraries -> Add -> Java -> Select core.jar that i create before and OK -> Library 'core' will be added to the selected modules. (android) OK -> And OK in the Project Structure Dialog.
构建 - >重建项目
15错误 20警告
所有的错误都是错误:需要不断前pression和 我看Error在ZXing项目的切换例机器人 我改变所有交换机上的,如果别人的。
All errors are error: constant expression required and I see Error in Switch cases of ZXing project in android I change all switchs for if elses.
0错误 20警告
好了,现在继续:
文件 - >新建项目 - > zxing_demo下一步 - >下一步 - >空白活动下一步 - >完成
File -> New project -> zxing_demo Next -> Next -> Blank Activity Next -> Finish
在新项目 - >文件 - >导入模块 - >搜索和选择/安卓/确定 - >创建一个从现有的资源模块下一步 - >下一步 - >下一步 - >下一步 - >完成
In new project -> File -> Import module -> Search and select /android/ OK -> Create module from existing sources Next -> Next -> Next -> Next -> Finish
现在我可以在资源管理器中看到/安卓/ / zging_demoProject /和外部的库
Now I can see in the explorer /android/ /zging_demoProject/ and External Libraries
现在我改变我的code涂扫描QR
Now i change my code tu scan QR
AndroidManifest.xml中
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zxing_demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.zxing_demo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:configChanges="orientation|keyboardHidden"
android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter >
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
MainActivity.java
MainActivity.java
package com.example.zxing_demo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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
}
}
}
}
现在测试,运行 - >调试
Now test, Run -> Debug
和崩溃。
logcat的
08-31 02:58:28.085 20665-20665/com.example.zxing_demo E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.zxing_demo/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
... 11 more
我可以在AndroidManifest.xml中看到这一行
I can see in AndroidManifest.xml in this line
android:name="com.google.zxing.client.android.CaptureActivity"
CaptureActivity红色和错误说:无法解析符号CaptureActivity
"CaptureActivity" in red and the error say: Cannot resolve symbol 'CaptureActivity'
文件 - >项目结构 - >模块 - > zxing_demo - >相关性 - >添加 - >模块依赖 - > Android的确定 - >应用和确定
File -> Project Structure -> Modules -> zxing_demo -> Dependencies -> Add -> Module dependency -> android OK -> Apply and OK
现在CaptureActivity看起来不错
Now CaptureActivity looks good
再次调试
08-31 03:06:58.513 21740-21740/com.example.zxing_demo E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.zxing_demo/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
... 11 more
我觉得我去使用的应用程序和意图,但现在我想做好这项工作,如果有人现在什么发生请告诉我:D谢谢
I think i go use the application and intents, but now i want do this work, if someone now whats happen tell me please :D Thanks!
推荐答案
好男人,因为我今天的任务是整合ZXING到一个Android应用程序,并有输入没有很好的来源都结束了,我会给你一个提示什么让我获得成功 - ,因为它原来是很容易
Okay guys, as my task today was to integrate ZXING into an Android application and there were no good sources for input all over, I will give you a hint what made me be successful - because it turned out to be very easy.
有一个真正的方便的git仓库,提供了zxing的Android库项目为AAR存档。
There is a real handy git repository that provides the zxing android library project as an AAR archive.
https://github.com/journeyapps/zxing-android-embedded所有你需要做的就是它添加到您的build.gradle
All you have to do is add this to your build.gradle
repositories {
jcenter()
}
dependencies {
compile 'com.journeyapps:zxing-android-embedded:3.0.2@aar'
compile 'com.google.zxing:core:3.2.0'
}
和摇篮做所有的魔法编译code,使得它在你的应用程序进行访问。
and Gradle does all the magic to compile the code and makes it accessible in your app.
要算账启动扫描仪,使用这个类/方法: 从活动:
To start the Scanner afterwards, use this class/method: From the Activity:
new IntentIntegrator(this).initiateScan(); // `this` is the current Activity
这是一个片段:
IntentIntegrator.forFragment(this).initiateScan(); // `this` is the current Fragment
// If you're using the support library, use IntentIntegrator.forSupportFragment(this) instead.
有几个自定义选项:
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
integrator.setPrompt("Scan a barcode");
integrator.setCameraId(0); // Use a specific camera of the device
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
integrator.initiateScan();
他们有一个 样本项目 ,并提供多种集成的例子:
They have a sample-project and are providing several integration examples:
AnyOrientationCaptureActivity ContinuousCaptureActivity CustomScannerActivity ToolbarCaptureActivity AnyOrientationCaptureActivity ContinuousCaptureActivity CustomScannerActivity ToolbarCaptureActivity如果你已经访问过你会看到,我只是复制和链接,粘贴从混帐自述的code。如果没有,去那里得到一些更深入的了解和code例子!
If you already visited the link you gonna see that i just copy&pasted the code from the git README. If not, go there to get some more insight and code examples!
希望对未来的读者有所帮助。和平:)
Hope to be helpful for future readers. Peace :)
相关推荐
最新文章