This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Home
Alistair Sykes edited this page Mar 11, 2020
·
6 revisions
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)
Please do raise issues for suggesting improvements to this wiki.