Как я могу узнать, когда спусковой крючок пистолета нажат программно, с помощью Zebra DataWedge 11.3.28, используя транслятор намерений на RFD40 + TC21?
Я использую один из примеров от Zebra
Как я могу узнать, когда спусковой крючок пистолета нажат программно, с помощью Zebra DataWedge 11.3.28, используя транслятор намерений на RFD40 + TC21? Я использую один из примеров от Zebra [code]object DataWedgeUtility { private const val PROFILE_NAME = "DW_my_app" private const val ACTION_DATAWEDGE = "com.symbol.datawedge.api.ACTION" private const val EXTRA_CREATE_PROFILE = "com.symbol.datawedge.api.CREATE_PROFILE" private const val EXTRA_SET_CONFIG = "com.symbol.datawedge.api.SET_CONFIG"
fun createDWProfile(context: Context) { sendDataWedgeIntentWithExtra( context, ACTION_DATAWEDGE, EXTRA_CREATE_PROFILE, PROFILE_NAME )
val profileConfig = Bundle() profileConfig.putString("PROFILE_NAME", PROFILE_NAME) profileConfig.putString("PROFILE_ENABLED", "true") // Seems these are all strings profileConfig.putString("CONFIG_MODE", "UPDATE") val rfidConfig = Bundle() rfidConfig.putString("PLUGIN_NAME", "RFID") rfidConfig.putString("RESET_CONFIG", "true")
val rfidProps = Bundle() /* values true o false as string */ rfidProps.putString("rfid_input_enabled", "true") /* values true o false as string */ rfidProps.putString("rfid_beeper_enable", "true") /* Integer from 5 to 30 */ rfidProps.putString("rfid_antenna_transmit_power", "25")
rfidConfig.putBundle("PARAM_LIST", rfidProps) profileConfig.putBundle("PLUGIN_CONFIG", rfidConfig) val appConfig = Bundle() appConfig.putString( "PACKAGE_NAME", context.packageName ) // Associate the profile with this app appConfig.putStringArray("ACTIVITY_LIST", arrayOf("*")) profileConfig.putParcelableArray("APP_LIST", arrayOf(appConfig)) sendDataWedgeIntentWithExtra(context, ACTION_DATAWEDGE, EXTRA_SET_CONFIG, profileConfig)
// You can only configure one plugin at a time, we have done the RFID input, 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", context.resources.getString(R.string.activity_intent_filter_action) )
private fun sendDataWedgeIntentWithExtra( context: Context, action: String, extraKey: String, extras: Bundle ) { val dwIntent = Intent() dwIntent.action = action dwIntent.putExtra(extraKey, extras) context.sendBroadcast(dwIntent) } } [/code] А в действии у меня есть следующий код [code]class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) DataWedgeUtility.createDWProfile(this) ... }
override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) val action = intent.action
if (action == resources.getString(R.string.activity_intent_filter_action)) { // Received a RFID scan try { val epc = intent.getStringExtra( resources.getString(R.string.datawedge_intent_key_data) ) if (epc?.isNotBlank() == true){ val tagList = epc.split("\n") tagList.forEach { EventBus.getDefault().post(TagReadEvent(epc = it)) } } } catch (e: Exception) { // Catch if the UI does not exist when we receive the broadcast } } }
fun softRfidTrigger(): Boolean{ val dwIntent = Intent() dwIntent.action = "com.symbol.datawedge.api.ACTION" // Button released, end scan when { !readingFlag -> { readingFlag = true dwIntent.putExtra( "com.symbol.datawedge.api.SOFT_RFID_TRIGGER", "START_SCANNING" ) } else -> { readingFlag = false dwIntent.putExtra( "com.symbol.datawedge.api.SOFT_RFID_TRIGGER", "STOP_SCANNING" ) } } sendBroadcast(dwIntent) return readingFlag } .. } [/code] Я использую в приложении подход с одним действием, и весь обмен данными между действием и фрагментами осуществляется с помощью событий EventBus.