ScanCodeView is a library to scan code for android app
- Scan barCode and QR code
- Scan multi-code at the same time
- Support to auto-focus by tap
- Support to show focus view after tap
- Add it in your root
build.gradleat the end of repositories
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}- Add the dependency
dependencies {
...
def camerax_version = '1.0.0-beta10'
implementation "androidx.camera:camera-core:$camerax_version"
// CameraX Camera2 extensions
implementation "androidx.camera:camera-camera2:$camerax_version"
// CameraX Lifecycle library
implementation "androidx.camera:camera-lifecycle:$camerax_version"
// CameraX View class
implementation 'androidx.camera:camera-view:1.0.0-alpha17'
implementation 'com.github.ijkzen:ScanCodeView:<latest_version>'
}To use this library, you must change Applicatioin class like below.
class MyApplication: Application(), CameraXConfig.Provider {
companion object {
private lateinit var instance: MyApplication
fun instance() = instance
}
override fun onCreate() {
super.onCreate()
instance = this
}
override fun getCameraXConfig(): CameraXConfig {
return Camera2Config.defaultConfig()
}
}
// bind camera resource to lifecycle, must be called before initCamera()
// context must be Application or Activity
fun setLifecycle(owner: LifecycleOwner, context: Context)
// initialize camera to scan code
fun initCamera()
// release cache data to avoid memory leak
fun releaseCamera()
// open flash if torch is available
fun openFlash()
// close flash if torch is available
fun closeFlash()
// continue to scan code or not
fun setContinue(continueScan: Boolean)
// callback for scan result
fun setResultListener(listener: ScanResultListener)
// show focus view for tap or not
fun setShowFocusCircle(show: Boolean)
If you have any questions, please ask me here
