Skip to content
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ useEffect(() => {

- Developer docs: https://en.urovo.com/developer/index.html
- Example projects with Java package: https://github.com/urovosamples/SDK_ReleaseforAndroid/tree/master/Samples/ScanManager (All example usage was written in Java, the logic for this module has been written in Kotlin and exposed as an Expo module.)

## Timeline

v.10 works!
v.12 attempt to get sound working
v.13 perf gains
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import expo.modules.kotlin.modules.ModuleDefinition
// Import Urovo SDK classes (Java classes) in Kotlin
import android.device.ScanManager

// Attempt: Add Beep func
// import android.device.scanner.configuration.PropertyID

// Import Android framework classes
import android.content.BroadcastReceiver
import android.content.Context
Expand Down Expand Up @@ -40,16 +43,53 @@ class ExpoUrovoScannerModule : Module() {
}

Function("scanner") {
mScanManager = ScanManager()
var powerOn = mScanManager?.scannerState

mScanManager?.switchOutputMode(0) // DECODE_OUTPUT_MODE_INTENT = 0

registerReceiver()
if (mScanManager == null) {
try {
mScanManager = ScanManager()
var powerOn = mScanManager?.scannerState

mScanManager?.switchOutputMode(0) // DECODE_OUTPUT_MODE_INTENT = 0

// Attempt to add beep, uncommented it for now, not sure if it's working
// val index = intArrayOf(PropertyID.GOOD_READ_BEEP_ENABLE)
// val value = intArrayOf(1)
// mScanManager?.setParameterInts(index, value)

registerReceiver()
Log.d("ExpoUrovoScannerModule", "Scanner initialized successfully")
} catch (e: Exception) {
Log.e("ExpoUrovoScannerModule", "Failed to initialize scanner: ${e.message}")
throw e
}
} else {
Log.d("ExpoUrovoScannerModule", "Scanner already initialized")
}
}

Function("scan") {
mScanManager?.startDecode()
try {
if (mScanManager == null) {
throw Exception("Scanner not initialized. Call scanner() first.")
}
mScanManager?.startDecode()
Log.d("ExpoUrovoScannerModule", "Scan started")
} catch (e: Exception) {
Log.e("ExpoUrovoScannerModule", "Failed to start decode: ${e.message}")
throw e
}
}

Function("stopScan") {
try {
if (mScanManager == null) {
throw Exception("Scanner not initialized. Call scanner() first.")
}
mScanManager?.stopDecode()
Log.d("ExpoUrovoScannerModule", "Scan stopped")
} catch (e: Exception) {
Log.e("ExpoUrovoScannerModule", "Failed to stop decode: ${e.message}")
throw e
}
}

// Defines a JavaScript function that always returns a Promise and whose native code
Expand All @@ -62,7 +102,13 @@ class ExpoUrovoScannerModule : Module() {
}

OnDestroy {
try {
mScanManager?.stopDecode() // Stop any ongoing decode operations
} catch (e: Exception) {
Log.w("ExpoUrovoScannerModule", "Error stopping decode on destroy: ${e.message}")
}
unregisterReceiver()
mScanManager = null
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "expo-urovo-scanner-module",
"version": "0.10.0",
"version": "0.13.0",
"description": "A Expo Module that communicates with Urovo scanners",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down