Hallo zusammen,
ich bin dabei den Barcode-Scanner in eine App zu integrieren ohne ZXing als einzelne sprich parallel installierte App laufen zu haben.
Ich habe mich dabei an diesen beiden Tutorials orentiert:
Allerdings funktioniert die App nach beiden Anleitungen nicht.
Tutorial 1:
Integrate zxing barcode scanner into your Android app natively using Eclipse Damian Flannery's Blog
barcode.xml
[XML]<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android
rientation="vertical" >
<Button
android:id="@+id/btn_barcode_scannen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_barcode_scannen"
android
nClick="onClick" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tv_barcode" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tv_Typ" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
</LinearLayout>[/XML]
Es wird ein Intent ausgelöst. also kann ich wählen, mit welcher App ich den Barcode scannen will. Wähle ich "Barcode Scanner", friert die App ein und folgender Fehler taucht auf:
Tutorial 2:
ZXing QR Reader Direct Integration | AndroidAZ
ScannerActivity:
[XML]<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android
rientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<FrameLayout
android:layout_width="200dip"
android:layout_height="200dip"
android:layout_gravity="center_horizontal">
<include layout="@layout/capture"/>
</FrameLayout>
</LinearLayout>[/XML]
Fehler der bei der xml angezeigt wird:
Wenn ich auf den Hyperlink klicke "(ViewfinderView.java:66)", werde ich auf diese Klasse gelenkt (Diese gehört allerdings zu dem ZXing, ein anderes Projekt, das ich nur importiert habe):
Folgende Fehlermeldung tritt auf:
Das Projekt kann man sich auch auf der Seite unten downloaden. Das ZXing sollte ich korrekt eingebunden haben, wie auch die core.jar erstellt etc. Leider kann ich die Projekte nicht anhängen, da die Dateien zu groß sind (auch gezippt). Wenn noch irgendwas fehlt, werde ich das nachliefern. Ich hoffe ihr könnt mir helfen
Danke schon im Voraus
ich bin dabei den Barcode-Scanner in eine App zu integrieren ohne ZXing als einzelne sprich parallel installierte App laufen zu haben.
Ich habe mich dabei an diesen beiden Tutorials orentiert:
- Integrate zxing barcode scanner into your Android app natively using Eclipse Damian Flannery's Blog
- ZXing QR Reader Direct Integration | AndroidAZ
Allerdings funktioniert die App nach beiden Anleitungen nicht.
Tutorial 1:
Integrate zxing barcode scanner into your Android app natively using Eclipse Damian Flannery's Blog
Java:
package de.novatec.novathek;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class Barcode extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.barcode);
}
public void onClick(final View view) {
switch (view.getId()) {
case R.id.btn_barcode_scannen:
System.out.println("onClick 1");
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
System.out.println("onClick 2");
break;
}
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
System.out.println("onActivityResult");
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
System.out.println("onActivityResult - 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
System.out.println("onActivityResult _ RESULT_CANCELD");
}
}
}
}
barcode.xml
[XML]<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android
<Button
android:id="@+id/btn_barcode_scannen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_barcode_scannen"
android
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tv_barcode" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tv_Typ" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
</LinearLayout>[/XML]
Es wird ein Intent ausgelöst. also kann ich wählen, mit welcher App ich den Barcode scannen will. Wähle ich "Barcode Scanner", friert die App ein und folgender Fehler taucht auf:
Code:
01-23 16:58:26.530: W/dalvikvm(12470): Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/google/zxing/client/android/CaptureActivity;
01-23 16:58:26.530: W/dalvikvm(12470): Class init failed in newInstance call (Lcom/google/zxing/client/android/CaptureActivity;)
01-23 16:58:26.530: D/AndroidRuntime(12470): Shutting down VM
01-23 16:58:26.530: W/dalvikvm(12470): threadid=1: thread exiting with uncaught exception (group=0x41e9f2a0)
01-23 16:58:26.535: E/AndroidRuntime(12470): FATAL EXCEPTION: main
01-23 16:58:26.535: E/AndroidRuntime(12470): java.lang.ExceptionInInitializerError
01-23 16:58:26.535: E/AndroidRuntime(12470): at java.lang.Class.newInstanceImpl(Native Method)
01-23 16:58:26.535: E/AndroidRuntime(12470): at java.lang.Class.newInstance(Class.java:1319)
01-23 16:58:26.535: E/AndroidRuntime(12470): at android.app.Instrumentation.newActivity(Instrumentation.java:1057)
01-23 16:58:26.535: E/AndroidRuntime(12470): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015)
01-23 16:58:26.535: E/AndroidRuntime(12470): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
01-23 16:58:26.535: E/AndroidRuntime(12470): at android.app.ActivityThread.access$600(ActivityThread.java:140)
01-23 16:58:26.535: E/AndroidRuntime(12470): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
01-23 16:58:26.535: E/AndroidRuntime(12470): at android.os.Handler.dispatchMessage(Handler.java:99)
01-23 16:58:26.535: E/AndroidRuntime(12470): at android.os.Looper.loop(Looper.java:137)
01-23 16:58:26.535: E/AndroidRuntime(12470): at android.app.ActivityThread.main(ActivityThread.java:4898)
01-23 16:58:26.535: E/AndroidRuntime(12470): at java.lang.reflect.Method.invokeNative(Native Method)
01-23 16:58:26.535: E/AndroidRuntime(12470): at java.lang.reflect.Method.invoke(Method.java:511)
01-23 16:58:26.535: E/AndroidRuntime(12470): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
01-23 16:58:26.535: E/AndroidRuntime(12470): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
01-23 16:58:26.535: E/AndroidRuntime(12470): at dalvik.system.NativeStart.main(Native Method)
01-23 16:58:26.535: E/AndroidRuntime(12470): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType
01-23 16:58:26.535: E/AndroidRuntime(12470): at com.google.zxing.client.android.CaptureActivity.<clinit>(CaptureActivity.java:101)
01-23 16:58:26.535: E/AndroidRuntime(12470): ... 15 more
Tutorial 2:
ZXing QR Reader Direct Integration | AndroidAZ
ScannerActivity:
Java:
package com.androidaz.scanner;
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.main);
}
@Override
public void handleDecode(Result rawResult, Bitmap barcode)
{
Toast.makeText(this.getApplicationContext(), "Scanned code " + rawResult.getText(), Toast.LENGTH_LONG);
}
}
[XML]<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<FrameLayout
android:layout_width="200dip"
android:layout_height="200dip"
android:layout_gravity="center_horizontal">
<include layout="@layout/capture"/>
</FrameLayout>
</LinearLayout>[/XML]
Fehler der bei der xml angezeigt wird:
Code:
The following classes could not be instantiated:
- com.google.zxing.client.android.ViewfinderView (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.
android.content.res.Resources$NotFoundException: Could not resolve resource value: 0x7F07000A.
at android.content.res.BridgeResources.throwException(BridgeResources.java:693)
at android.content.res.BridgeResources.getColor(BridgeResources.java:185)
at com.google.zxing.client.android.ViewfinderView.<init>(ViewfinderView.java:66)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0( at sun.reflect.NativeConstructorAccessorImpl.newInstance( at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( at java.lang.reflect.Constructor.newInstance( at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:413)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:170)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:746)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
at android.view.LayoutInflater_Delegate.parseInclude(LayoutInflater_Delegate.java:154)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:773)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:736)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:749)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:372)
Wenn ich auf den Hyperlink klicke "(ViewfinderView.java:66)", werde ich auf diese Klasse gelenkt (Diese gehört allerdings zu dem ZXing, ein anderes Projekt, das ich nur importiert habe):
Java:
/*
* Copyright (C) 2008 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* [url]http://www.apache.org/licenses/LICENSE-2.0[/url]
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.android;
import com.google.zxing.ResultPoint;
import com.google.zxing.client.android.camera.CameraManager;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import java.util.ArrayList;
import java.util.List;
/**
* This view is overlaid on top of the camera preview. It adds the viewfinder rectangle and partial
* transparency outside it, as well as the laser scanner animation and result points.
*
* @author [email]dswitkin@google.com[/email] (Daniel Switkin)
*/
public final class ViewfinderView extends View {
private static final int[] SCANNER_ALPHA = {0, 64, 128, 192, 255, 192, 128, 64};
private static final long ANIMATION_DELAY = 80L;
private static final int CURRENT_POINT_OPACITY = 0xA0;
private static final int MAX_RESULT_POINTS = 20;
private static final int POINT_SIZE = 6;
private CameraManager cameraManager;
private final Paint paint;
private Bitmap resultBitmap;
private final int maskColor;
private final int resultColor;
private final int laserColor;
private final int resultPointColor;
private int scannerAlpha;
private List<ResultPoint> possibleResultPoints;
private List<ResultPoint> lastPossibleResultPoints;
// This constructor is used when the class is built from an XML resource.
public ViewfinderView(Context context, AttributeSet attrs) {
super(context, attrs);
// Initialize these once for performance rather than calling them every time in onDraw().
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
Resources resources = getResources();
maskColor = resources.getColor(R.color.viewfinder_mask); // Zeile 66
resultColor = resources.getColor(R.color.result_view);
laserColor = resources.getColor(R.color.viewfinder_laser);
resultPointColor = resources.getColor(R.color.possible_result_points);
scannerAlpha = 0;
possibleResultPoints = new ArrayList<ResultPoint>(5);
lastPossibleResultPoints = null;
}
public void setCameraManager(CameraManager cameraManager) {
this.cameraManager = cameraManager;
}
@Override
public void onDraw(Canvas canvas) {
if (cameraManager == null) {
return; // not ready yet, early draw before done configuring
}
Rect frame = cameraManager.getFramingRect();
if (frame == null) {
return;
}
int width = canvas.getWidth();
int height = canvas.getHeight();
// Draw the exterior (i.e. outside the framing rect) darkened
paint.setColor(resultBitmap != null ? resultColor : maskColor);
canvas.drawRect(0, 0, width, frame.top, paint);
canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
canvas.drawRect(0, frame.bottom + 1, width, height, paint);
if (resultBitmap != null) {
// Draw the opaque result bitmap over the scanning rectangle
paint.setAlpha(CURRENT_POINT_OPACITY);
canvas.drawBitmap(resultBitmap, null, frame, paint);
} else {
// Draw a red "laser scanner" line through the middle to show decoding is active
paint.setColor(laserColor);
paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length;
int middle = frame.height() / 2 + frame.top;
canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint);
Rect previewFrame = cameraManager.getFramingRectInPreview();
float scaleX = frame.width() / (float) previewFrame.width();
float scaleY = frame.height() / (float) previewFrame.height();
List<ResultPoint> currentPossible = possibleResultPoints;
List<ResultPoint> currentLast = lastPossibleResultPoints;
int frameLeft = frame.left;
int frameTop = frame.top;
if (currentPossible.isEmpty()) {
lastPossibleResultPoints = null;
} else {
possibleResultPoints = new ArrayList<ResultPoint>(5);
lastPossibleResultPoints = currentPossible;
paint.setAlpha(CURRENT_POINT_OPACITY);
paint.setColor(resultPointColor);
synchronized (currentPossible) {
for (ResultPoint point : currentPossible) {
canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX),
frameTop + (int) (point.getY() * scaleY),
POINT_SIZE, paint);
}
}
}
if (currentLast != null) {
paint.setAlpha(CURRENT_POINT_OPACITY / 2);
paint.setColor(resultPointColor);
synchronized (currentLast) {
float radius = POINT_SIZE / 2.0f;
for (ResultPoint point : currentLast) {
canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX),
frameTop + (int) (point.getY() * scaleY),
radius, paint);
}
}
}
// Request another update at the animation interval, but only repaint the laser line,
// not the entire viewfinder mask.
postInvalidateDelayed(ANIMATION_DELAY,
frame.left - POINT_SIZE,
frame.top - POINT_SIZE,
frame.right + POINT_SIZE,
frame.bottom + POINT_SIZE);
}
}
public void drawViewfinder() {
Bitmap resultBitmap = this.resultBitmap;
this.resultBitmap = null;
if (resultBitmap != null) {
resultBitmap.recycle();
}
invalidate();
}
/**
* Draw a bitmap with the result points highlighted instead of the live scanning display.
*
* @param barcode An image of the decoded barcode.
*/
public void drawResultBitmap(Bitmap barcode) {
resultBitmap = barcode;
invalidate();
}
public void addPossibleResultPoint(ResultPoint point) {
List<ResultPoint> points = possibleResultPoints;
synchronized (points) {
points.add(point);
int size = points.size();
if (size > MAX_RESULT_POINTS) {
// trim it
points.subList(0, size - MAX_RESULT_POINTS / 2).clear();
}
}
}
}
Folgende Fehlermeldung tritt auf:
Code:
01-23 17:09:34.505: W/dalvikvm(24175): VFY: unable to find class referenced in signature (Lcom/google/zxing/PlanarYUVLuminanceSource;)
01-23 17:09:34.510: W/dalvikvm(24175): VFY: Ljava/lang/Object; is not instance of Lcom/google/zxing/LuminanceSource;
01-23 17:09:34.510: W/dalvikvm(24175): VFY: bad arg 1 (into Lcom/google/zxing/LuminanceSource;)
01-23 17:09:34.510: W/dalvikvm(24175): VFY: rejecting call to Lcom/google/zxing/common/HybridBinarizer;.<init> (Lcom/google/zxing/LuminanceSource;)V
01-23 17:09:34.510: W/dalvikvm(24175): VFY: rejecting opcode 0x70 at 0x001d
01-23 17:09:34.510: W/dalvikvm(24175): VFY: rejected Lcom/google/zxing/client/android/DecodeHandler;.decode ([BII)V
01-23 17:09:34.510: W/dalvikvm(24175): Verifier rejected class Lcom/google/zxing/client/android/DecodeHandler;
01-23 17:09:34.510: W/dalvikvm(24175): threadid=14: thread exiting with uncaught exception (group=0x41e9f2a0)
01-23 17:09:34.550: D/dalvikvm(24175): GC_CONCURRENT freed 202K, 6% free 12728K/13511K, paused 44ms+37ms, total 103ms
01-23 17:09:34.560: E/AndroidRuntime(24175): FATAL EXCEPTION: Thread-3946
01-23 17:09:34.560: E/AndroidRuntime(24175): java.lang.VerifyError: com/google/zxing/client/android/DecodeHandler
01-23 17:09:34.560: E/AndroidRuntime(24175): at com.google.zxing.client.android.DecodeThread.run(DecodeThread.java:92)
01-23 17:09:34.770: I/PlatformSupportManager(24175): Using implementation class com.google.zxing.client.android.common.executor.HoneycombAsyncTaskExecInterface of interface com.google.zxing.client.android.common.executor.AsyncTaskExecInterface for SDK 11
01-23 17:09:34.775: I/AutoFocusManager(24175): Current focus mode 'auto'; use auto focus? true
Das Projekt kann man sich auch auf der Seite unten downloaden. Das ZXing sollte ich korrekt eingebunden haben, wie auch die core.jar erstellt etc. Leider kann ich die Projekte nicht anhängen, da die Dateien zu groß sind (auch gezippt). Wenn noch irgendwas fehlt, werde ich das nachliefern. Ich hoffe ihr könnt mir helfen
Danke schon im Voraus