An awsome library that contains ML Kit and Camrax implementation! You don't need ZXing anymore.
Report Bug
·
Request Feature
Table of Contents
No need to waste time on CameraX and ML Kit app anymore. This library will speed up your development 100%
Features:
- CameraX image capturing
- Ml-Kit barcode scanning with accuracy algorithm.
- Flash, tap to focus, switch back-front camera.
- Stop-start ML Kit barcode reading and camera.
- Run without google play services
- Add maven-jitpack into project level gradle file.
repositories { ... maven { url 'https://jitpack.io' } }
- Add this into dependencies which is in module level gradle file.
dependencies { ... implementation 'com.github.furkanturkn:camerax-mlkit-pack:1.1.2' }
- Get camera permission.
- Init CameraxManager for activity
Init CameraxManager for fragment
cameraxManager = CameraxManager.getInstance( this, null, previewView, focusRing, //(ImageView) image that appears with focus animation when clicked on the screen. 1 //(Int)(optional) start with FRONT[0] or BACK[1] camera. Default = BACK[1]. )
cameraxManager = CameraxManager.getInstance( context, this, previewView, focusRing, //(ImageView) image that appears with focus animation when clicked on the screen. 1 //(Int)(optional) start with FRONT[0] or BACK[1] camera. Default = BACK[1]. )
- Destroy references.
override fun onDestroy() { super.onDestroy() cameraxManager?.destroyReferences() }
-
How to start camera?
cameraxManager.startCamera()
-
How to start barcode reading?
cameraxManager?.setReaderFormats( ReaderType.FORMAT_QR_CODE.value, ReaderType.FORMAT_EAN_8.value, ReaderType.FORMAT_EAN_13.value, . . . ) cameraxManager?.startReading()
-
How to stop reading and camera?
cameraxManager?.stopReading() cameraxManager?.stopCamera()
-
How to change flash status?
cameraxManager.changeFlashStatus()
-
How to change camera type (front-back)?
cameraxManager.changeCameraType()
-
How to capture photo?
cameraxManager.capturePhoto()
-
How to change accuracy level of barcode reading?
cameraxManager.setReadingAccuracyLevel(levelOfAccuracy)
levelOfAccuracy = 1 (Less accurate, fastest level. If you select only QR type the accuracy level is automatically set to 1.)
levelOfAccuracy = 2 (Minimum requirement for correct barcode reading.)
levelOfAccuracy = 3 (Recommended and default accuracy level.)
For product barcodes:
ReaderType.FORMAT_EAN_8.value
ReaderType.FORMAT_EAN_13.value
ReaderType.FORMAT_UPC_E.value
ReaderType.FORMAT_UPC_A.value
For QR codes:
ReaderType.FORMAT_QR_CODE.value
cameraxManager?.apply {
setQrReadSuccessListener { result ->
println("QR RESULT ----------> $result")
tvReadResult.text = result
}
setFlashStatusChangedListener { status ->
when (status) {
FlashStatus.ENABLED -> {
btnFlash.setBackgroundResource(R.drawable.baseline_flash_on_24)
}
FlashStatus.DISABLED -> {
btnFlash.setBackgroundResource(R.drawable.baseline_flash_off_24)
}
}
}
setPhotoCaptureResultListener { capturedBitmap ->
runOnUiThread {
ivCapturePreview.setImageBitmap(capturedBitmap)
}
}
}