blinkcard / blinkcard-android

SDK for scanning and OCR of credit or payment cards. Contains native Android SDK, code samples and documentation.
45 stars 5 forks source link

Documentation outdated, onActivityResult is now deprecated #22

Closed damolaobaleke closed 1 year ago

damolaobaleke commented 2 years ago

Description

When using ActivityResultsLauncher, which is the new method of passing information back and forth between activities. a method which is then passed into RegisterForActivityResult(), which i have defined and is meant to process the data, isn't being called.

Basically the api and documentation doesn't suite the new android api for passing info back and forth between activities. onActivityResult() is now old and deprecated

 @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), this::onScanActivityResult);

    }

public void onScanActivityResult(ActivityResult result) {
        if (result.getResultCode() == Activity.RESULT_OK) {
            if (result.getData() != null && selectedId.equals("Drivers License")) {
                if(!result.getData().hasExtra("mrzResult")) {//then drivers license

                    recognizerBundle.loadFromIntent(result.getData());

                    recognizerResult = blinkIdRecognizer.getResult();

                    if (recognizerResult.getResultState() == Recognizer.Result.State.Valid) {
                        //alert dialog to show it, then save it
                        StringBuilder builder = new StringBuilder();
                        builder.append(recognizerResult.getFirstName()).append(recognizerResult.getLastName()).append(recognizerResult.getSex()).append(recognizerResult.getAddress())
                                .append(recognizerResult.getAge()).append(recognizerResult.getDateOfBirth().getDate());

                        Log.i(TAG, builder.toString());

                        ProcessingStatus processingStatus = recognizerResult.getProcessingStatus();
                        if (processingStatus.equals(ProcessingStatus.Success)) {
                            Log.i(TAG, "Processing successful");

                        } else {
                            Log.i(TAG, "Processing unsuccessful");
                        }

                    } else {
                        //Toast
                        Toast.makeText(requireContext(), "Result gotten was invalid", Toast.LENGTH_SHORT).show();
                    }
                }else {
                    //scan for visa or passport
                    //TODO: Find unique identifier for visa or passport
                }
            }
        }

    }

Environment Details

BlinkCard version: com.microblink:blinkcard:2.5*

Device model: Samsung SM-A307FN Device Android version: Android 11, Api 30 Device ABI (processor architecture, e.g. ARMv7): ARMv7

Log file

Please enable logging by following instructions here and attach full log file.

Additional information

I think the READ.md just has to be updated on how to get information back from scan when using ActivityResultsLauncher as onActivityResult is now deprecated

mparadina commented 2 years ago

Hi @damolaobaleke

Yes, even though the onActivityResult is deprecated, you could still use it since it will work on all Android API levels, and there should not be any issues using it. Also to add, we intend to add the support for ActivityResultsLauncher and the new Android API for passing the information between activities for future releases.

Please let me know if you have any additional questions.

damolaobaleke commented 2 years ago

@mparadina alright then, no worries. Thanks I'd use the deprecated method and see if it works. Thanks!

damolaobaleke commented 2 years ago

@mparadina Works fine

krizaa commented 2 years ago

@damolaobaleke Hi, in the new version of BlinkCard v2.6.0 you can use the new Activity Result API to launch the scan activity and handle results. Check out our sample app to see how to implement it :)

damolaobaleke commented 2 years ago

@damolaobaleke Hi, in the new version of BlinkCard v2.6.0 you can use the new Activity Result API to launch the scan activity and handle results. Check out our sample app to see how to implement it :)

@krizaa Thanks, I'll check out the new sdk version and use the new api.