Meryl D'Souza
Meryl D'Souza

Reputation: 61

Unable to implement QR code Reader in my android app

I am trying to implement a QR code reader in my android app. I have followed these steps:

  1. Created a sample library project from the zxing.zip , /android and /core

  2. Added the created library to my app

My code is as below :

public class main extends Activity {
/** Called when the activity is first created. */

Button scanButton;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

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

    scanButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // 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
        }
    }
}

The scanner doesn't start and I get this error:

05-08 14:12:03.313: ERROR/AndroidRuntime(718): Caused by: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity in loader dalvik.system.PathClassLoader[/data/app/com.scanner.demo-2.apk]

The manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.scanner.demo" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".main" 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>

Upvotes: 0

Views: 1259

Answers (2)

Sean Owen
Sean Owen

Reputation: 66891

This is quite confused. You seem to be wanting to integrate by Intent, which is what the first half does. But then you seem to have copied our Manifest. Why? Please remove that. It's not needed, causes your error, and if you leave it in, interferes with our app.

This is all you need: https://code.google.com/p/zxing/wiki/ScanningViaIntent

Upvotes: 2

Peter Lo
Peter Lo

Reputation: 110

Why do you put this in your Manifest?

<activity 
    android:name="com.google.zxing.client.android.CaptureActivity"
...
</activity>

Are you calling internal activity or the App from Zxing?

Upvotes: 2

Related Questions