Closed koai-dev closed 2 years ago
You're probably calling startScan in the wrong place
startScan
This should work
package com.your.project import android.graphics.BitmapFactory import android.os.Bundle import android.util.Log import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity import com.websitebeaver.documentscanner.DocumentScanner class MainActivity : AppCompatActivity() { private lateinit var croppedImageView: ImageView private val documentScanner = DocumentScanner( this, { croppedImageResults -> // display the first cropped image croppedImageView.setImageBitmap( BitmapFactory.decodeFile(croppedImageResults.first()) ) }, { // an error happened errorMessage -> Log.v("documentscannerlogs", errorMessage) }, { // user canceled document scan Log.v("documentscannerlogs", "User canceled document scan") } ) val getDocumentScan = this.registerForActivityResult( ActivityResultContracts.StartActivityForResult() ) { result: ActivityResult -> documentScanner.handleDocumentScanIntentResult(result) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // cropped image croppedImageView = findViewById(R.id.cropped_image_view) } fun onClickStartScanButton(view: View) { getDocumentScan.launch(documentScanner.createDocumentScanIntent()) } }
this doesnt work onclick doesnt launch the camera for scanning
Yesss, it works <3
You're probably calling
startScan
in the wrong placeThis should work