vlasentiy / Lens24

📷 Library for scanning and OCR of credit or payment cards
MIT License
9 stars 4 forks source link

when you scan your card on Android 13, it doesn't extract any detail. no error messages as well #1

Open RhymezxCode opened 7 months ago

RhymezxCode commented 7 months ago

I used this method, no luck

    private fun scanCard() {
        val intent: Intent = ScanCardIntent.Builder(this)
            // customize these values to suit your needs
            .setHint("Please kindly scan your card")
            .setToolbarTitle("Scan your card")
            .setSaveCard(true)
            .setBottomHint("Please kindly place your card in the box above!")
            .setMainColor(R.color.colorPrimary)
            .build()
        startActivityIntent.launch(intent)
    }
vlasentiy commented 7 months ago

Hi, could you please show me full code of Activity where you try to use it ? Do you have a problem only on Android 13?

RhymezxCode commented 7 months ago

I currently use Android 13 so that is when noticed it. The demo app on google play also have the same problem, try testing on Android 13 or 14

vlasentiy commented 7 months ago

Then you use demo app from Google Play, did scanner "catch" your card and next screen "Card details" is with empty fields or scanner can't "catch" card?

RhymezxCode commented 7 months ago

The camera fully captures the card, but it doesn't leave that screen, even after waiting for a long time. Not detail page is opened as well

vlasentiy commented 7 months ago

What card type do you use? Lens24 supports only Visa and MC (16 digits), but not American Express, JCB

RhymezxCode commented 7 months ago

I tested with a MasterCard and Visa card.

RhymezxCode commented 7 months ago

@vlasentiy there you go

class CardOptionSelection : AppCompatActivity(), View.OnClickListener {
    private lateinit var binding: ActivityCardOptionSelectionBinding

    //bundle data
    private var bundle: Bundle = Bundle()

    private var activityResultCallback = ScanCardCallback.Builder()
        .setOnSuccess { card: Card, bitmap: Bitmap? -> setCard(card) }
        .setOnBackPressed { finish() }
        .setOnError {
            Snackbar.make(
                findViewById(android.R.id.content),
                "Something went wrong!",
                Snackbar.LENGTH_LONG
            ).show()
        }
        .build()

    private var startActivityIntent = registerForActivityResult(
        ActivityResultContracts.StartActivityForResult(),
        activityResultCallback
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
        binding = ActivityCardOptionSelectionBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.cardNumber.setOnClickListener(this)
        binding.cardOcr.setOnClickListener(this)
    }

    private fun setCard(card: Card) {
        bundle.putString("cardNumber", card.cardNumber)
        startActivity(
            Intent(
                this,
                OCRconfirm::class.java
            ).putExtras(bundle)
        )
    }

    private fun scanCard() {
        val intent: Intent = ScanCardIntent.Builder(this)
            // customize these values to suit your needs
            .setVibrationEnabled(true)
            .setHint("Please kindly scan your card")
            .setToolbarTitle("Scan your card")
            .setSaveCard(false)
            .setBottomHint("Please kindly place your card in the box above!")
            .setMainColor(R.color.colorPrimary)
            .build()
        startActivityIntent.launch(intent)
    }

    override fun onClick(v: View?) {
        if (v != null) {
            when (v.id) {
                R.id.card_number -> startActivity(Intent(this,
                    CardProcessor::class.java))
                R.id.card_ocr -> {
                    scanCard()
                }
            }
        }
    }
}