I want to integrate zxing scanner into my app without needed of external application (zxing scanner from play store). This is my code
Button scan = (Button) findViewById(R.id.scan_button);
scan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.mypackage.app");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, SCANNER_REQUEST_CODE);
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == SCANNER_REQUEST_CODE) {
// Handle scan intent
if (resultCode == Activity.RESULT_OK) {
// Handle successful scan
String contents = intent.getStringExtra("SCAN_RESULT");
String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
int intentOrientation = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE);
Integer orientation = (intentOrientation == Integer.MIN_VALUE) ? null : intentOrientation;
String errorCorrectionLevel = intent.getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL");
} else if (resultCode == Activity.RESULT_CANCELED) {
// Handle cancel
}
} else {
// Handle other intents
}
}
AndroidManifest.xml
<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="com.google.zxing.client.android.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
My Android Studio said that cannot resolve symbol: .android.CaptureActivity
and if I run this, error happened
java.lang.ClassNotFoundException: Didn't find class "com.google.zxing.client.android.CaptureActivity"
What happened?
I don't know why it happened, but finally I use another library. I use Zxing-android-minimal and tutorial from here and here. Now it works.