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?