Introduction
From the last few years, we noticed that the QA/BR Code has become universal for advertisement, product information, and marketing. Simply we can say QR code is an image-like data matrix. The message/text given by QR code after scanning could be a website link or production contact information.
Below example that contains URL of Anviam Solution.
The main purpose of this blog that we should learn how to integrate QR code in your android application. Before we start this blog, don’t miss checking the https://play.google.com/store/apps/details?id=com.anviam.barcodescanner develop by our app programmer.
Steps to peruse QR/BR Code in Android
First of every, create a new project in Android studio.
Next, need to add in root Gradle file as following :
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
In your app module Gradle file just need to add the dependency
dependencies
{
implementation 'com.github.AnviamSolutions:QR-Barcode-Scanner:1.0.1'
}
Add camera permission to AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.FLASHLIGHT"/>
Add frame layout into your activity xml
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
In Your activity, initialize Scanner
ViewGroup contentFrame = (ViewGroup) findViewById(R.id.content_frame);
mScannerView = new AnviamScannerView(this);
contentFrame.addView(mScannerView);
In Your activity, Declare handle result
@Override
public void onResume() {
super.onResume();
if (mScannerView!=null)
mScannerView.setResultHandler(rawResult -> {
if (rawResult!=null && !TextUtils.isEmpty(rawResult.getText())){
//Todo method to get can content
}
});
if (mScannerView!=null){
mScannerView.setCameraFacing(ToggleButtonCamera.isChecked());
}
}
@Override
public void onPause() {
super.onPause();
if (mScannerView!=null)
mScannerView.stopCamera();
}
Flip Camera (Back/Front)
mScannerView.setCameraFacing(false);
Flash Light(On/Off)
mScannerView.setFlashLight(false);
Commendation!
if you are following the same step, moreover you will strongly integrate QR-Barcode scanner in the android application. Anyway, if face any problem you can see the link https://github.com/AnviamSolutions/QR-Barcode-Scanner