-
Notifications
You must be signed in to change notification settings - Fork 16
Home
Add the dependency to your build.gradle
implementation 'uk.co.brightec.kbarcode:kbarcode:$version'
For the latest version see releases or bintray
If you wish to use Android Architecture Components, see https://developer.android.com/topic/libraries/architecture for installation details.
You will need to have Firebase setup in your project. See Firebase documentation for a guide to this.
Add a BarcodeView
into your layout
<uk.co.brightec.kbarcode.BarcodeView
android:id="@+id/view_barcode"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
You can use the available XML attributes to customise the behaviour. See reference for details on these.
Add the BarcodeView
as an observer to your lifecycle in onCreate()
lifecycle.addObserver(barcodeView)
Add an observer to the BarcodeView
LiveData
barcodeView.barcodes.observe(viewLifecycleOwner, Observer { barcodes ->
// ...
})
A good place for this is just below the line adding a lifecycle observer
You can also add the BarcodeView
programmatically
barcodeView = BarcodeView(this)
barcodeView.setOptions(
Options.Builder()
.cameraFacing(CameraCharacteristics.LENS_FACING_BACK)
.barcodeFormats(
intArrayOf(
Barcode.FORMAT_CODABAR, Barcode.FORMAT_EAN_13, Barcode.FORMAT_EAN_8,
Barcode.FORMAT_ITF, Barcode.FORMAT_UPC_A, Barcode.FORMAT_UPC_E
)
)
.barcodesSort(null)
.scaleType(BarcodeView.CENTER_INSIDE)
.build()
)
frameContainer.addView(barcodeView)
Depending on your usage/configuration you may need to add this to your proguard-rules.pro
:
-keep class uk.co.brightec.kbarcode.** { *; }
Please do raise issues for suggesting improvements to this wiki.