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)
I am really late but I wish to reply on this for someone else to be helped later. This is not to say that the above methods and solution are wrong, Its just an additional info so, for the developer he/she will choose the better way. It is good to have thousand way to go than having one.
So, let's start into our gradle and add
compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
compile 'com.google.zxing:core:3.2.1'
Calling the module like (eg: on button click):
IntentIntegrator integrator = new IntentIntegrator(Home.this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
integrator.setPrompt("Scan Code");
integrator.setCameraId(0);
integrator.setBeepEnabled(true);
integrator.setBarcodeImageEnabled(false);
integrator.initiateScan();
Get the results like:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(intentResult != null) {
if(intentResult.getContents() == null) {
Log.d("MainActivity", "Cancelled");
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Log.d("MainActivity", "Scanned");
Toast.makeText(this, "Scanned: " + intentResult.getContents(), Toast.LENGTH_LONG).show();
}
}
}
For more info you can check the link https://github.com/pethoalpar/ZxingExample
Elaborating stackex's answer.... Create an activity with any name.
public class CaptureActivityAnyOrientation extends CaptureActivity {
}
In manifest define the desired orientation or leave like below to work in both landscape and portait.
<activity android:name=".CaptureActivityAnyOrientation"
android:screenOrientation="fullSensor"
android:stateNotNeeded="true"
android:theme="@style/zxing_CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden"/>
Finally use the activity created as setCaptureActivity.
IntentIntegrator.forSupportFragment(fragment)
.setCaptureActivity(CaptureActivityAnyOrientation.class)
.setOrientationLocked(false)
.setBeepEnabled(true)
.addExtra("PROMPT_MESSAGE", "Scan QR Code")
.initiateScan(IntentIntegrator.QR_CODE_TYPES);
Hope this helps.