How To Create Barcode Scanner in Android Studio
1 min readOct 21, 2018
Hello friends, in this post I will discuss about how to create a barcode code detection program in Android Studio
So, this program will scan a barcode using a camera and will display the results. First, open Android Studio and create a new project. When done, go to dependencies section and enter the following libraries
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.journeyapps:zxing-android-embedded:3.4.0'
}
Next, create a layout and name it activity_main, then enter the following code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
tools:context="id.ndiappink.scannerbarcode.MainActivity">
<Button
android:id="@+id/buttonScan"
android:layout_alignParentBottom="true"
android:text="Scan Your Barcode"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Next, create a new class and name it Portrait so that the program can be run in portrait mode. then extends with CaptureActivity
import com.journeyapps.barcodescanner.CaptureActivity;
public class Portrait extends CaptureActivity {}