Android Zxing ActivityNotFoundException

时间:2015-04-11 01:27:34

标签: android zxing

这是我的第一个Android应用程序,所以我可能会把一切都弄错。我本质上是C#,我正在将下面的错误消息解释为相当于dll中缺少的void。但我试图找到我能做到的每一个例子,而我却无法弄清楚如何让它发挥作用。

我只有1个目标,制作一个带有1个按钮的Android应用程序当我点击它时启动Zxing中不需要安装额外应用程序的QR扫描程序

但这是我得到的错误 04-10 21:12:15.380 30818-30818/com.example.mycomp.zxingapp E/AndroidRuntime﹕ FATAL EXCEPTION: main android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN (has extras) }

我已下载https://github.com/zxing/zxing/archive/zxing-3.2.0.zip并使用mvn -DskipTests -Dgpg.skip=true install构建它。然后我将.jar拖放到我的libs文件夹中。

这是我的activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Scan"
    android:id="@+id/scanButton"
    android:layout_below="@+id/textView"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="97dp" />

AndroidManifest.xml          

<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="22"/>
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".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:name="com.google.zxing.client.android.CaptureActivity"
        android:screenOrientation="landscape"
        android:configChanges="orientation|keyboardHidden"
        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

package com.example.mycomp.zxingapp;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;


public class MainActivity extends ActionBarActivity {
private Button scan;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    scan= (Button)findViewById(R.id.scanButton);

    scan.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            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
            Log.i("App","Scan unsuccessful");
        }
    }
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

public void clickButton(View v) {


    Button but = (Button)v;
    ((Button)v).setText("woot woot");
}




}

build.gradle是的,这是app

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.example.mycomp.zxingapp"
    minSdkVersion 8
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
}

欢迎任何帮助

ugh

1 个答案:

答案 0 :(得分:0)

core-3.2.0.jar 仅用于解码,它不会执行任何拍照 - 然后 - 然后 - 解码和显示结果的东西。因此,您尝试启动的活动( com.google.zxing.client.android.CaptureActivity )并不存在于jar文件中。

要做你想要达到的目标,你需要提取和修改 /zxing-zxing-3.2.0/android 中的代码,&# 39;其中 com.google.zxing.client.android.CaptureActivity 以及它使用的所有支持类所在的位置。我的建议是导入整件事,慢慢切掉你不需要的课程。