I'm using ZXing
Library this way:
repositories {
mavenCentral()
maven {
url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.zxing:core:2.2'
compile 'com.embarkmobile:zxing-android-minimal:1.2.1@aar'
}
And in Activity
:
IntentIntegrator.initiateScan(this);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
} else {
// This is important, otherwise the result will not be passed to the fragment
super.onActivityResult(requestCode, resultCode, data);
}
}
And it looks like this:
But I don't know how to add a back button on this camera preview. How can I create a custom layout with camera on background and back button on front?
I had this problem a while back so finally I borrowed and customised the code from Andreas Schildbach bitcoin wallet. This will create a small camera view in the screen while you have other views.
I put the gist here.
Its a QRCode scanner and there are buttons and EditText around it. Also it has a an overlay rectangle for better finding the middle of the screen.