jak pomoże Ci coś z Kotlina :
w manifest mam tylko coś takiego :
<receiver android:name=".DWReceiver" android:enabled="true" android:exported="true" />
przykładowo Intent listą towarów :
private lateinit var connectionBroadcastReceiver: DWReceiver;
w onCreate :
connectionBroadcastReceiver = object : DWReceiver() {
override fun broadcastResult(kod: String) {
_kod.value=kod;
handler?.sendEmptyMessage(5);
}
}
rejestrujReciver();
fun rejestrujReciver() {
if (!connectionBroadcastReceiver.register) {
// Register broadcast receiver to listen for responses from DW API
val intentFilter = IntentFilter()
intentFilter.addAction(DWInterface.DATAWEDGE_SCAN_EXTRA_DATA_STRING);
intentFilter.addAction(MainActivity.PROFILE_INTENT_ACTION);
registerReceiver(connectionBroadcastReceiver, intentFilter)
connectionBroadcastReceiver.register = true;
}
}
override fun onDestroy() {
super.onDestroy()
if (connectionBroadcastReceiver.register) {
unregisterReceiver(connectionBroadcastReceiver)
connectionBroadcastReceiver.register = false;
}
client.dispose();
}
taką klase mam :
package com.netsoft.magazynxl
import android.content.Context
import android.content.Intent
import android.os.Bundle
class DWInterface()
{
companion object {
const val DATAWEDGE_SEND_ACTION = "com.symbol.datawedge.api.ACTION"
const val DATAWEDGE_RETURN_ACTION = "com.symbol.datawedge.api.RESULT_ACTION"
const val DATAWEDGE_RETURN_CATEGORY = "android.intent.category.DEFAULT"
const val DATAWEDGE_EXTRA_SEND_RESULT = "SEND_RESULT"
const val DATAWEDGE_EXTRA_RESULT = "RESULT"
const val DATAWEDGE_EXTRA_COMMAND = "COMMAND"
const val DATAWEDGE_EXTRA_RESULT_INFO = "RESULT_INFO"
const val DATAWEDGE_EXTRA_RESULT_CODE = "RESULT_CODE"
const val DATAWEDGE_SCAN_EXTRA_DATA_STRING = "com.symbol.datawedge.data_string"
const val DATAWEDGE_SCAN_EXTRA_LABEL_TYPE = "com.symbol.datawedge.label_type"
const val DATAWEDGE_SEND_CREATE_PROFILE = "com.symbol.datawedge.api.CREATE_PROFILE"
const val DATAWEDGE_SEND_GET_VERSION = "com.symbol.datawedge.api.GET_VERSION_INFO"
const val DATAWEDGE_RETURN_VERSION = "com.symbol.datawedge.api.RESULT_GET_VERSION_INFO"
const val DATAWEDGE_RETURN_VERSION_DATAWEDGE = "DATAWEDGE"
const val DATAWEDGE_SEND_GET_ENUMERATE_SCANNERS = "com.symbol.datawedge.api.ENUMERATE_SCANNERS"
const val DATAWEDGE_RETURN_ENUMERATE_SCANNERS = "com.symbol.datawedge.api.RESULT_ENUMERATE_SCANNERS"
const val DATAWEDGE_SEND_GET_CONFIG = "com.symbol.datawedge.api.GET_CONFIG"
const val DATAWEDGE_RETURN_GET_CONFIG = "com.symbol.datawedge.api.RESULT_GET_CONFIG"
const val DATAWEDGE_SEND_SET_CONFIG = "com.symbol.datawedge.api.SET_CONFIG"
const val DATAWEDGE_SEND_GET_ACTIVE_PROFILE = "com.symbol.datawedge.api.GET_ACTIVE_PROFILE"
const val DATAWEDGE_RETURN_GET_ACTIVE_PROFILE = "com.symbol.datawedge.api.RESULT_GET_ACTIVE_PROFILE"
const val DATAWEDGE_SEND_SWITCH_SCANNER = "com.symbol.datawedge.api.SWITCH_SCANNER"
const val DATAWEDGE_SEND_SET_SCANNER_INPUT = "com.symbol.datawedge.api.SCANNER_INPUT_PLUGIN"
const val DATAWEDGE_SEND_SET_SCANNER_INPUT_ENABLE = "ENABLE_PLUGIN"
const val DATAWEDGE_SEND_SET_SCANNER_INPUT_DISABLE = "DISABLE_PLUGIN"
const val DATAWEDGE_SEND_SET_SOFT_SCAN = "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER"
}
fun sendCommandString(context: Context, command: String, parameter: String, sendResult: Boolean = false)
{
val dwIntent = Intent()
dwIntent.action = DATAWEDGE_SEND_ACTION
dwIntent.putExtra(command, parameter)
if (sendResult)
dwIntent.putExtra(DATAWEDGE_EXTRA_SEND_RESULT, "true")
context.sendBroadcast(dwIntent)
}
fun sendCommandBundle(context: Context, command: String, parameter: Bundle)
{
val dwIntent = Intent()
dwIntent.action = DATAWEDGE_SEND_ACTION
dwIntent.putExtra(command, parameter)
context.sendBroadcast(dwIntent)
}
fun setConfigForDecoder(context: Context, profileName: String, ean8Value: Boolean,
ean13Value: Boolean, code39Value: Boolean, code128Value: Boolean,
illuminationValue: String, picklistModeValue: String) {
val profileConfig = Bundle()
profileConfig.putString("PROFILE_NAME", profileName)
profileConfig.putString("PROFILE_ENABLED", "true")
profileConfig.putString("CONFIG_MODE", "UPDATE")
val barcodeConfig = Bundle()
barcodeConfig.putString("PLUGIN_NAME", "BARCODE")
barcodeConfig.putString("RESET_CONFIG", "true")
val barcodeProps = Bundle()
barcodeProps.putString("scanner_selection", "auto")
barcodeProps.putString("decoder_ean8", "" + ean8Value)
barcodeProps.putString("decoder_ean13", "" + ean13Value)
barcodeProps.putString("decoder_code39", "" + code39Value)
barcodeProps.putString("decoder_code128", "" + code128Value)
barcodeProps.putString("illumination_mode", illuminationValue)
barcodeProps.putString("picklist", picklistModeValue)
barcodeConfig.putBundle("PARAM_LIST", barcodeProps)
profileConfig.putBundle("PLUGIN_CONFIG", barcodeConfig)
sendCommandBundle(context, DATAWEDGE_SEND_SET_CONFIG, profileConfig)
}
}
i taką :
package com.netsoft.magazynxl
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
abstract class DWReceiver : BroadcastReceiver() {
var register:Boolean=false;
override fun onReceive(context: Context, intent: Intent) {
// This method is called when the BroadcastReceiver is receiving an Intent broadcast.
// Notify registered observers
// ObservableObject.instance.updateValue(intent)
if (intent.hasExtra(DWInterface.DATAWEDGE_SCAN_EXTRA_DATA_STRING))
{
var scanData = intent.getStringExtra(DWInterface.DATAWEDGE_SCAN_EXTRA_DATA_STRING)
broadcastResult(scanData.toString());
}
if (intent.hasExtra(DWInterface.DATAWEDGE_EXTRA_RESULT_INFO ))
{
}
}
protected abstract fun broadcastResult(kod:String)
}
a tak tworzę własny profil
private fun createDataWedgeProfile() {
// Create and configure the DataWedge profile associated with this application
// For readability's sake, I have not defined each of the keys in the DWInterface file
dwInterface.sendCommandString(this, DWInterface.DATAWEDGE_SEND_CREATE_PROFILE,
MainActivity.PROFILE_NAME
)
val profileConfig = Bundle()
profileConfig.putString("PROFILE_NAME", MainActivity.PROFILE_NAME)
profileConfig.putString("PROFILE_ENABLED", "true") // These are all strings
profileConfig.putString("CONFIG_MODE", "UPDATE")
val barcodeConfig = Bundle()
barcodeConfig.putString("PLUGIN_NAME", "BARCODE")
barcodeConfig.putString("RESET_CONFIG", "true") // This is the default but never hurts to specify
val barcodeProps = Bundle()
barcodeProps.putString("scanner_input_enabled", "true")
barcodeConfig.putBundle("PARAM_LIST", barcodeProps)
profileConfig.putBundle("PLUGIN_CONFIG", barcodeConfig)
val appConfig = Bundle()
appConfig.putString("PACKAGE_NAME", packageName) // Associate the profile with this app
appConfig.putStringArray("ACTIVITY_LIST", arrayOf("*"))
profileConfig.putParcelableArray("APP_LIST", arrayOf(appConfig))
dwInterface.sendCommandBundle(this, DWInterface.DATAWEDGE_SEND_SET_CONFIG, profileConfig)
// You can only configure one plugin at a time in some versions of DW, now do the intent output
profileConfig.remove("PLUGIN_CONFIG")
val intentConfig = Bundle()
intentConfig.putString("PLUGIN_NAME", "INTENT")
intentConfig.putString("RESET_CONFIG", "true")
val intentProps = Bundle()
intentProps.putString("intent_output_enabled", "true")
intentProps.putString("intent_action", MainActivity.PROFILE_INTENT_ACTION)
intentProps.putString("intent_delivery", MainActivity.PROFILE_INTENT_START_ACTIVITY)
intentConfig.putBundle("PARAM_LIST", intentProps)
profileConfig.putBundle("PLUGIN_CONFIG", intentConfig)
dwInterface.sendCommandBundle(this, DWInterface.DATAWEDGE_SEND_SET_CONFIG, profileConfig)
profileConfig.remove("PLUGIN_CONFIG")
val bundleKSOutConfig = Bundle()
bundleKSOutConfig.putString("PLUGIN_NAME", "KEYSTROKE")
bundleKSOutConfig.putString("RESET_CONFIG", "false")
val bundleKSParams = Bundle()
bundleKSParams.putString("keystroke_output_enabled", "false")
bundleKSOutConfig.putBundle("PARAM_LIST", bundleKSParams)
profileConfig.putBundle("PLUGIN_CONFIG", bundleKSOutConfig)
dwInterface.sendCommandBundle(this, DWInterface.DATAWEDGE_SEND_SET_CONFIG, profileConfig)
}
Sorry że troche bałaganu ale może się przyda