PDA broadcasts support two transmission modes:
- Focus Mode - displays data inline
- Broadcast Mode - sends data via system broadcast
The appropriate mode depends on device capabilities and application requirements.
For this implementation, broadcast mode was selected. Focus mode consistently triggers the system keyboard, and no reliable workaround was identified.
Create a new file pdaScan.ts:
export class BroadcastScanManager {
private activityContext: any
private intentFilter: any
private scanReceiver: any
private isProcessing = false
constructor() {}
initialize(callback: (scanResult: string) => void): void {
this.activityContext = plus.android.runtimeMainActivity()
const IntentFilterClass = plus.android.importClass('android.content.IntentFilter')
this.intentFilter = new IntentFilterClass()
this.intentFilter.addAction('broadcast_action_identifier')
const instance = this
this.scanReceiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
onReceive: function (context: any, intent: any) {
plus.android.importClass(intent)
const scanResult = intent.getStringExtra('extra_key_identifier')
// Prevent duplicate processing within short interval
if (instance.isProcessing) return
instance.isProcessing = true
setTimeout(() => {
instance.isProcessing = false
}, 150)
// Handle successful scan - code contains the scanned value
callback && callback(scanResult)
},
})
}
enable(): void {
if (this.scanReceiver) {
this.activityContext.registerReceiver(this.scanReceiver, this.intentFilter)
}
}
disable(): void {
if (this.scanReceiver) {
this.activityContext.unregisterReceiver(this.scanReceiver)
}
}
}
Import and use the scanner in pages requiring scan monitoring:
import { BroadcastScanManager } from '@/utils/pdaScan'
const scanner = new BroadcastScanManager()
const scannedCode = ref<string>('')
onMounted(() => {
const handleScanResult = (code: string) => {
console.log('Scanned:', code)
scannedCode.value = code
}
scanner.initialize(handleScanResult)
})
onShow(() => {
scanner.enable()
})
onUnmounted(() => {
scanner.disable()
})
onHide(() => {
scanner.disable()
})
Configuration Notes:
broadcast_action_identifier- Set this to match the broadcast action name configured in the PDA device settingsextra_key_identifier- Set this to match the intent extra key defined in the device developer options
These values must align with the corresponding settings configured on the physical PDA hardware device.