Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example_app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dependencies {
implementation("androidx.constraintlayout:constraintlayout:2.1.4")


def sdkVersion = "8.0.0.49-STAGING-SNAPSHOT"
def sdkVersion = "8.0.0.51-STAGING-SNAPSHOT"

implementation("io.scanbot:scanbot-barcode-scanner-sdk:$sdkVersion")
implementation("io.scanbot:rtu-ui-v2-barcode:$sdkVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.ComposeView
import androidx.core.view.WindowCompat
import io.scanbot.common.Result
import io.scanbot.common.onFailure
import io.scanbot.example.sdk.barcode.R
import io.scanbot.sdk.ui_v2.barcode.BarcodeScannerView
import io.scanbot.sdk.ui_v2.barcode.configuration.BarcodeScannerConfiguration
import io.scanbot.sdk.ui_v2.barcode.configuration.BarcodeScannerScreenConfiguration
import io.scanbot.sdk.ui_v2.common.StatusBarMode
import io.scanbot.sdk.ui_v2.common.activity.AutoCancelTimeout
import io.scanbot.sdk.ui_v2.common.activity.CanceledByUser
import io.scanbot.sdk.ui_v2.common.activity.ForceClose
import io.scanbot.sdk.ui_v2.common.activity.LicenseInvalid
import io.scanbot.sdk.ui_v2.common.activity.SystemError

class AlmostRtuUiBarcodeScannerActivity : AppCompatActivity() {

Expand Down Expand Up @@ -73,16 +70,19 @@ class AlmostRtuUiBarcodeScannerActivity : AppCompatActivity() {
// TODO: present barcode result as needed.
},
onBarcodeScannerClosed = {
// Optional activity closing cause handling to understand the reason scanner result is not provided
when (it) {
LicenseInvalid -> Toast.makeText(
context,
"License has expired!",
Toast.LENGTH_LONG
).show()
AutoCancelTimeout -> Unit // just close screen (below)
CanceledByUser -> Unit // just close screen (below)
is SystemError -> Unit // handle system error here
ForceClose -> Unit // just close screen (below)
is Result.InvalidLicenseError -> {
// indicate that the Scanbot SDK license is invalid
}

is Result.OperationCanceledError -> {
// Indicates that the cancel button was tapped. or screen is closed by other reason.
}

else -> {
// Handle other errors
}
}
finish()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import androidx.appcompat.widget.AppCompatButton
import androidx.appcompat.app.AppCompatActivity
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import io.scanbot.common.Result
import io.scanbot.common.onFailure
import io.scanbot.common.onSuccess
// @Tag("Add imports for RTU UI v2 activity")
import io.scanbot.sdk.barcode_scanner.ScanbotBarcodeScannerSDKInitializer
import io.scanbot.sdk.ui_v2.barcode.BarcodeScannerActivity
Expand All @@ -42,16 +45,33 @@ class QuickStartSnippetActivity : AppCompatActivity() {
// @Tag("Register RTU UI v2 activity result launcher")
// The call to BarcodeScannerActivity.ResultContract() must be done after the SDK initialization
val barcodeScreenLauncher: ActivityResultLauncher<BarcodeScannerScreenConfiguration> =
registerForActivityResultOk(BarcodeScannerActivity.ResultContract()) { resultEntity ->
// Barcode Scanner result callback:
// Get the first scanned barcode from the result object...
val barcodeItem = resultEntity.result?.items?.first()
// ... and process the result as needed, for example, display as a Toast:
Toast.makeText(
this,
"Scanned: ${barcodeItem?.barcode?.text} (${barcodeItem?.barcode?.format})",
Toast.LENGTH_LONG
).show()
registerForActivityResult(BarcodeScannerActivity.ResultContract()) { resultEntity ->
resultEntity.onSuccess { result ->
// Barcode Scanner result callback:
// Get the first scanned barcode from the result object...
val barcodeItem = result?.items?.first()
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After successful result handling, result should not be nullable. Remove the null-safe operator: val barcodeItem = result.items.first() to match the pattern in other files.

Copilot uses AI. Check for mistakes.
// ... and process the result as needed, for example, display as a Toast:
Toast.makeText(
this@QuickStartSnippetActivity,
"Scanned: ${barcodeItem?.barcode?.text} (${barcodeItem?.barcode?.format})",
Toast.LENGTH_LONG
).show()
}.onFailure {
// Optional activity closing cause handling to understand the reason scanner result is not provided
when (it) {
is Result.InvalidLicenseError -> {
// indicate that the Scanbot SDK license is invalid
}

is Result.OperationCanceledError -> {
// Indicates that the cancel button was tapped. or screen is closed by other reason.
}

else -> {
// Handle other errors
}
}
}
}
// @EndTag("Register RTU UI v2 activity result launcher")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import androidx.appcompat.widget.AppCompatButton
import androidx.appcompat.app.AppCompatActivity
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import io.scanbot.common.Result
import io.scanbot.common.onFailure
import io.scanbot.common.onSuccess
import io.scanbot.sdk.barcode_scanner.ScanbotBarcodeScannerSDKInitializer
import io.scanbot.sdk.ui_v2.barcode.BarcodeScannerActivity
import io.scanbot.sdk.ui_v2.barcode.configuration.BarcodeScannerScreenConfiguration
Expand All @@ -38,16 +41,33 @@ class StartRtuUiActivitySnippetActivity : AppCompatActivity() {

// The call to BarcodeScannerActivity.ResultContract() must be done after the SDK initialization
val barcodeScreenLauncher: ActivityResultLauncher<BarcodeScannerScreenConfiguration> =
registerForActivityResultOk(BarcodeScannerActivity.ResultContract()) { resultEntity ->
// Barcode Scanner result callback:
// Get the first scanned barcode from the result object...
val barcodeItem = resultEntity.result?.items?.first()
// ... and process the result as needed, for example, display as a Toast:
Toast.makeText(
this,
"Scanned: ${barcodeItem?.barcode?.text} (${barcodeItem?.barcode?.format})",
Toast.LENGTH_LONG
).show()
registerForActivityResult(BarcodeScannerActivity.ResultContract()) { resultEntity ->
resultEntity.onSuccess { result ->
// Barcode Scanner result callback:
// Get the first scanned barcode from the result object...
val barcodeItem = result.items.first()
// ... and process the result as needed, for example, display as a Toast:
Toast.makeText(
this@StartRtuUiActivitySnippetActivity,
"Scanned: ${barcodeItem?.barcode?.text} (${barcodeItem?.barcode?.format})",
Toast.LENGTH_LONG
).show()
}.onFailure {
// Optional activity closing cause handling to understand the reason scanner result is not provided
when (it) {
is Result.InvalidLicenseError -> {
// indicate that the Scanbot SDK license is invalid
}

is Result.OperationCanceledError -> {
// Indicates that the cancel button was tapped. or screen is closed by other reason.
}

else -> {
// Handle other errors
}
}
}
}

val config = BarcodeScannerScreenConfiguration().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import androidx.appcompat.widget.AppCompatButton
import androidx.appcompat.app.AppCompatActivity
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import io.scanbot.common.Result
import io.scanbot.common.onFailure
import io.scanbot.common.onSuccess
// @Tag("Add imports for RTU UI v2 activity")
import io.scanbot.sdk.barcode_scanner.ScanbotBarcodeScannerSDKInitializer
import io.scanbot.sdk.geometry.AspectRatio
Expand Down Expand Up @@ -45,16 +48,33 @@ class ViewFinderSnippet : AppCompatActivity() {
// @Tag("Register RTU UI v2 activity result launcher")
// The call to BarcodeScannerActivity.ResultContract() must be done after the SDK initialization
val barcodeScreenLauncher: ActivityResultLauncher<BarcodeScannerScreenConfiguration> =
registerForActivityResultOk(BarcodeScannerActivity.ResultContract()) { resultEntity ->
// Barcode Scanner result callback:
// Get the first scanned barcode from the result object...
val barcodeItem = resultEntity.result?.items?.first()
// ... and process the result as needed, for example, display as a Toast:
Toast.makeText(
this,
"Scanned: ${barcodeItem?.barcode?.text} (${barcodeItem?.barcode?.format})",
Toast.LENGTH_LONG
).show()
registerForActivityResult(BarcodeScannerActivity.ResultContract()) { resultEntity ->
resultEntity.onSuccess { result ->
// Barcode Scanner result callback:
// Get the first scanned barcode from the result object...
val barcodeItem = result.items.first()
// ... and process the result as needed, for example, display as a Toast:
Toast.makeText(
this@ViewFinderSnippet,
"Scanned: ${barcodeItem?.barcode?.text} (${barcodeItem?.barcode?.format})",
Toast.LENGTH_LONG
).show()
}.onFailure {
// Optional activity closing cause handling to understand the reason scanner result is not provided
when (it) {
is Result.InvalidLicenseError -> {
// indicate that the Scanbot SDK license is invalid
}

is Result.OperationCanceledError -> {
// Indicates that the cancel button was tapped. or screen is closed by other reason.
}

else -> {
// Handle other errors
}
}
}
}
// @EndTag("Register RTU UI v2 activity result launcher")

Expand All @@ -63,9 +83,11 @@ class ViewFinderSnippet : AppCompatActivity() {
// Launch the barcode scanner:
val config = BarcodeScannerScreenConfiguration().apply {
viewFinder.visible = true // Show the view finder
viewFinder.aspectRatio = AspectRatio(16.0, 9.0) // Set the aspect ratio of the view finder
viewFinder.aspectRatio =
AspectRatio(16.0, 9.0) // Set the aspect ratio of the view finder
viewFinder.style = FinderStyle.finderCorneredStyle().apply {
strokeColor = ScanbotColor("#00FF00") // Set the color of the view finder corners
strokeColor =
ScanbotColor("#00FF00") // Set the color of the view finder corners
strokeWidth = 10.0 // Set the width of the view finder corners in dp
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import io.scanbot.common.Result
import io.scanbot.common.onFailure
import io.scanbot.common.onSuccess
import io.scanbot.example.sdk.barcode.R
import io.scanbot.example.sdk.barcode.databinding.ActivityMainBinding
import io.scanbot.example.sdk.barcode.model.BarcodeResultBundle
Expand Down Expand Up @@ -269,13 +272,30 @@ class MainActivity : AppCompatActivity() {
}

private val barcodeResultLauncher: ActivityResultLauncher<BarcodeScannerScreenConfiguration> =
registerForActivityResultOk(BarcodeScannerActivity.ResultContract()) { resultEntity ->
registerForActivityResult(BarcodeScannerActivity.ResultContract()) { resultEntity ->
resultEntity.onSuccess { result ->
BarcodeResultRepository.barcodeResultBundle =
BarcodeResultBundle(result)

val intent = Intent(this@MainActivity, BarcodeResultActivity::class.java)
startActivity(intent)
}.onFailure {
// Optional activity closing cause handling to understand the reason scanner result is not provided
when (it) {
is Result.InvalidLicenseError -> {
// indicate that the Scanbot SDK license is invalid
}

BarcodeResultRepository.barcodeResultBundle =
BarcodeResultBundle(resultEntity.result!!)
is Result.OperationCanceledError -> {
// Indicates that the cancel button was tapped. or screen is closed by other reason.
}

else -> {
// Handle other errors
}
}
}

val intent = Intent(this, BarcodeResultActivity::class.java)
startActivity(intent)
}

private val importImageResultLauncher: ActivityResultLauncher<Intent> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class QRScanCameraViewActivity : AppCompatActivity(), BarcodeScannerFrameHandler

override fun onResume() {
super.onResume()
barcodeScannerFrameHandler?.isEnabled = true
if (ContextCompat.checkSelfPermission(
this,
Manifest.permission.CAMERA
Expand All @@ -109,6 +110,9 @@ class QRScanCameraViewActivity : AppCompatActivity(), BarcodeScannerFrameHandler
}

private fun handleSuccess(result: BarcodeScannerResult) {
if (result.barcodes.isEmpty()) {
return
}
BarcodeResultRepository.barcodeResultBundle = BarcodeResultBundle(
BarcodeScannerUiResult(items = result.barcodes.map { it.toV2(1) }),
imagePath = null,
Expand Down Expand Up @@ -141,6 +145,7 @@ class QRScanCameraViewActivity : AppCompatActivity(), BarcodeScannerFrameHandler
): Boolean {
result.onSuccess {
handleSuccess(it)
barcodeScannerFrameHandler?.isEnabled = false
}.onFailure {
when (it) {
is Result.InvalidLicenseError -> {
Expand Down