项目作者: neyogiry

项目描述 :
Barcode scanner library for Android
高级语言: Kotlin
项目地址: git://github.com/neyogiry/barcodescanner.git
创建时间: 2020-02-02T22:16:05Z
项目社区:https://github.com/neyogiry/barcodescanner

开源协议:Apache License 2.0

下载


Barcode Scanner

Android library that provides easy to use and extensible Barcode Scanner views based on Google ML Kit.

Steps to add the library

  • Create a Firebase project in the Firebase console, if you don’t already have one
  • Add a new Android app into your Firebase project
  • Download the config file (google-services.json) from the new added app and move it into the module folder (i.e. app/)
  • Add camera permission to your AndroidManifest.xml file
    1. <uses-permission android:name="android.permission.CAMERA" ></uses-permission>
  • Add the following dependency to your build.gradle file
    1. repositories {
    2. jcenter()
    3. }
    ```groovy
    android {

    // BarcodeScanner requires Java 8.
    compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }
    }

dependencies {
implementation ‘com.neyogiry.scanner:barcode:0.1.0’
}

  1. ## Simple usage
  2. A very basic activity would look like this:
  3. ```kotlin
  4. class ScannerActivity : AppCompatActivity(), BarcodeScannerView.BarcodeResult {
  5. private var preview: CameraSourcePreview? = null
  6. private var graphicOverlay: GraphicOverlay? = null
  7. private var barcodeScanner: BarcodeScannerView? = null
  8. override fun onCreate(savedInstanceState: Bundle?) {
  9. super.onCreate(savedInstanceState)
  10. setContentView(R.layout.activity_scanner)
  11. preview = findViewById(R.id.camera_preview)
  12. graphicOverlay = findViewById<GraphicOverlay>(R.id.camera_preview_graphic_overlay)
  13. barcodeScanner = BarcodeScannerView(this)
  14. barcodeScanner?.onCreate(preview!!, graphicOverlay!!)
  15. barcodeScanner?.setBarcodeResult(this)
  16. }
  17. override fun onResume() {
  18. super.onResume()
  19. barcodeScanner?.onResume()
  20. }
  21. override fun onPause() {
  22. super.onPause()
  23. barcodeScanner?.onPause()
  24. }
  25. override fun onDestroy() {
  26. super.onDestroy()
  27. barcodeScanner?.onDestroy()
  28. }
  29. override fun onBarcodeResult(value: String) {
  30. Log.i(TAG, "The value is $value)
  31. }
  32. }

License

Licensed under an Apache-2 license.