markusfisch / BinaryEye

Yet another barcode scanner for Android
https://play.google.com/store/apps/details?id=de.markusfisch.android.binaryeye
MIT License
1.43k stars 117 forks source link

Update README with Activity.startActivityForResult #262

Closed alan-converge closed 2 years ago

alan-converge commented 2 years ago

Markus, I'm new to Kotlin and cannot replace the deprecated startActivityForResult with the new Activity.startActivityForResult. I've spent a few hours following online guides. No luck. Please refactor the snippet in the README.

markusfisch commented 2 years ago

Sorry, I know how frustrating this is 🙈 I've updated the README with the new, recommended way for AndroiX Activities:

class YourActivity : Activity() {
    private val resultLauncher = registerForActivityResult(StartActivityForResult()) { result ->
        if (result.resultCode == Activity.RESULT_OK) {
            val scan = result.data?.getStringExtra("SCAN_RESULT")
            // do something with "scan"
        }
    }

    fun openScanner() {
        resultLauncher.launch(Intent("com.google.zxing.client.android.SCAN"))
    }
}

There is a basic training is available at developer.android.com.