簡體   English   中英

Android Zxing ActivityNotFoundException

[英]Android Zxing ActivityNotFoundException

這是我的第一個android應用,所以我可能會把所有東西都弄錯了。 我本質上是C#,並且將以下錯誤消息解釋為dll中缺少空白的等效項。 但是我試圖找到我能找到的每個例子,但我不知道如何使它起作用。

我只有一個目標,要做一個帶有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'
}

歡迎任何幫助

啊

core-3.2.0.jar僅用於解碼 ,它不做任何拍照然后解碼和顯示結果的工作。 因此,您嘗試啟動的Activity( com.google.zxing.client.android.CaptureActivity )在jar文件中不存在。

要完成您想實現的目標,您需要提取和修改/zxing-zxing-3.2.0/android中的代碼, com.google.zxing.client.android.CaptureActivity及其使用的所有支持類均位於此位置。 我的建議是導入整個內容,並逐漸減少不需要的類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM