1

I want to add QRCode to my android application.

I am using Android Studio 8.1.

I download zxing core.jar file from maven repository (http://repo1.maven.org/maven2/com/google/zxing/core/3.1.0/)

I added following lines to my manifest xml file :

<uses-permission android:name="android.permission.CAMERA" />
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape" >
</activity>

then I added jar file to "lib" folder and I add as Library in gradle build file :

compile files('libs/core-3.1.0.jar')

And I created following Activity:

public class QrCodeReader extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qrcode);
        HandleClick hc = new HandleClick();
        findViewById(R.id.butQR).setOnClickListener(hc);
        findViewById(R.id.butProd).setOnClickListener(hc);
        findViewById(R.id.butOther).setOnClickListener(hc);
    }
    private class HandleClick implements View.OnClickListener {
        public void onClick(View arg0) {
           Intent intent = new Intent(getApplicationContext(),CaptureActivity.class);
            intent.setAction("com.google.zxing.client.android.SCAN");
            intent.putExtra("SAVE_HISTORY", false);
            startActivityForResult(intent, 0);


        }
    }
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == 0) {
            TextView tvStatus=(TextView)findViewById(R.id.tvStatus);
            TextView tvResult=(TextView)findViewById(R.id.tvResult);
            if (resultCode == RESULT_OK) {
                tvStatus.setText(intent.getStringExtra("SCAN_RESULT_FORMAT"));
                tvResult.setText(intent.getStringExtra("SCAN_RESULT"));
            } else if (resultCode == RESULT_CANCELED) {
                tvStatus.setText("Press a button to start a scan.");
                tvResult.setText("Scan cancelled.");
            }
        }
    }

}

Now I am getting "cannot resolve symbol CaptureActivity " error, how can I fix this?

Regards

EDIT :

I added following file and this error fixed

compile files('libs/android-core-3.1.0.jar') compile files('libs/android-integration-3.1.0.jar')

But I am getting following error :

java.lang.ClassNotFoundException: Didn't find class "com.google.zxing.client.android.CaptureActivity" How can I fix this?

onder
  • 795
  • 3
  • 14
  • 32
  • There are only three reasons you will ever get this error: The class genuinely doesn't exist. If you are using code from an official example and getting this, make sure you have the latest build of the library You have not added the jar to your build path. To fix this, right click on the jar in Eclipse, and do Build Path ► Add to Build Path. Your jar is not in the /libs folder. This happens when you have added the jar to the build path, but newer versions of ADT need it to be in /libs. Put it there and re-add it to the build path. – Sandeep Kumar Sep 24 '14 at 09:37

3 Answers3

1

You are not intended to use CaptureActivity in your application. It is not in core for this reason, and this is why your app can't find it.

Your code is confusing because you seem to want to integrate by Intent, but then, you have no need of any code in android or even core. Instead you should follow instructions at https://github.com/zxing/zxing/wiki/Scanning-Via-Intent

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • If I use following code it works, but I am getting this message : Install Barcode Scanner? I want to use qrcode scanner in my app, I dont want install any app. Can I do this? Thanks IntentIntegrator integrator = new IntentIntegrator(QrCodeReader.this); integrator.initiateScan(); – onder Sep 25 '14 at 09:25
  • Then you do not want to use `Intent`s. You need to write your own scanning application; please don't clone ours. But you should reuse `core/` and reuse parts of the `android/` source if you like. Just don't copy and paste. We have so many problems with that already. – Sean Owen Sep 25 '14 at 11:56
0

add intent filters inside the capture activity.

<intent-filter>
     <action android:name="com.google.zxing.client.android.SCAN" />
     <category android:name="android.intent.category.DEFAULT" />
     </intent-filter>
williamj949
  • 11,166
  • 8
  • 37
  • 51
  • I added, but I am getting same error,build failed : Error:(27, 63) error: cannot find symbol class CaptureActivity – onder Sep 24 '14 at 09:29
-1

once refer this link http://wahidgazzah.olympe.in/integrating-zxing-in-your-android-app-as-standalone-scanner/

add this in AndroidManifest.xml

<activity
     android:name="com.google.zxing.client.android.CaptureActivity"
     android:configChanges="orientation|keyboardHidden"
     android:screenOrientation="landscape"
     android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
     android:windowSoftInputMode="stateAlwaysHidden" >
     <intent-filter>
         <action android:name="com.google.zxing.client.android.SCAN" />
         <category android:name="android.intent.category.DEFAULT" />
     </intent-filter>
 </activity>
Sandeep Kumar
  • 350
  • 4
  • 18
  • I added, but I am getting same error,build failed : Error:(27, 63) error: cannot find symbol class CaptureActivity – onder Sep 24 '14 at 09:30
  • java.lang.ClassNotFoundException: Didn't find class "com.google.zxing.client.android.CaptureActivity" How can I fix this – onder Sep 24 '14 at 12:29