Профиль создан, но с DataWedge Zebra TC25 не связаны приложения.

Я работаю на устройствах Zebra TC25, пытаюсь создать профиль с помощью API DataWedge программно. Профиль создан, и я попытался отсканировать штрих-код, но ничего не произошло. Я проверил свое приложение DataWedge (версия 7.0.4), зашел в свой профиль и проверил, нет ли связанных приложений. У меня есть образец кода, который отлично работает, тот же пример кода, примененный в моем рабочем проекте, не работает. Если кто-то может помочь, будет большая экономия времени. Размещаю здесь мой код, пожалуйста, посмотрите.

DatawedgeManager.kt

class DatawedgeManager(val context: Context) {

private val dwInterface = DWInterface();



companion object {
    @Volatile
    private var instance: DatawedgeManager? = null
    const val PROFILE_NAME = "DataWedgePf"
    const val PROFILE_INTENT_ACTION = BuildConfig.APPLICATION_ID
    const val PROFILE_INTENT_START_ACTIVITY = "0"


    fun getInstance(context: Context): DatawedgeManager? {
        return instance ?: synchronized(DatawedgeManager::class.java) {
            if (instance == null) {
                instance = DatawedgeManager(context )
            }
            return instance
        }
    }

}




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(context, DWInterface.DATAWEDGE_SEND_CREATE_PROFILE, PROFILE_NAME)
    val profileConfig = Bundle()
    profileConfig.putString("PROFILE_NAME", 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()
    barcodeConfig.putBundle("PARAM_LIST", barcodeProps)
    profileConfig.putBundle("PLUGIN_CONFIG", barcodeConfig)
    val appConfig = Bundle()
    appConfig.putString("PACKAGE_NAME", BuildConfig.APPLICATION_ID)      //  Associate the profile with this app
    appConfig.putStringArray("ACTIVITY_LIST", arrayOf("*"))
    profileConfig.putParcelableArray("APP_LIST", arrayOf(appConfig))
    dwInterface.sendCommandBundle(context, 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", PROFILE_INTENT_ACTION)
    intentProps.putString("intent_delivery", PROFILE_INTENT_START_ACTIVITY)  //  "0"
    intentConfig.putBundle("PARAM_LIST", intentProps)
    profileConfig.putBundle("PLUGIN_CONFIG", intentConfig)
    dwInterface.sendCommandBundle(context, DWInterface.DATAWEDGE_SEND_SET_CONFIG, profileConfig)
    initScan()
}

fun initZebraLaserScan(){
    createDataWedgeProfile()
}

fun initScan(){

    dwInterface.sendCommandString(context, DWInterface.DATAWEDGE_SEND_SET_SCANNER_INPUT, DWInterface.DATAWEDGE_SEND_SET_SCANNER_INPUT_ENABLE)

}

fun deinitScan(){

    dwInterface.sendCommandString(context, DWInterface.DATAWEDGE_SEND_SET_SCANNER_INPUT,
        DWInterface.DATAWEDGE_SEND_SET_SCANNER_INPUT_DISABLE)

}
}

DWInterface.kt

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)
}
}

ViewpagerActivity.kt

class ViewPagerActivity : AppCompatActivity(), onPageChangeListener, SubscribeScanner {

private lateinit var mainViewModel: MainViewModel
private var listOfScreenObj = arrayListOf<String>()
lateinit var barcodeScannedEvent: BarcodeScannedEvent


override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.view_pager_layout)
    setSupportActionBar(toolbar)

    val dataViewModelFactory = DataViewModelFactory(this)
    mainViewModel = ViewModelProviders.of(this, dataViewModelFactory).get(MainViewModel::class.java)
    listOfScreenObj = mainViewModel.getScreenIds()
    setViewPager()

}


private fun setViewPager() {
    viewPager2.adapter = ViewPagerAdapter(this,listOfScreenObj)
    viewPager2.registerOnPageChangeCallback(pageChangeCallback)
}

private var pageChangeCallback = object : ViewPager2.OnPageChangeCallback() {
    override fun onPageSelected(position: Int) {
       Toast.makeText(this@ViewPagerActivity , "Selected position: $position", Toast.LENGTH_SHORT).show()
    }
}

override fun onPageChange(position: Int) {
    viewPager2.currentItem = position
}


override fun subscribeListener(barcodeScannedEvent: BarcodeScannedEvent) {
    this.barcodeScannedEvent = barcodeScannedEvent
}

override fun onNewIntent(intent: Intent) {
    super.onNewIntent(intent)
    if (intent.hasExtra(DWInterface.DATAWEDGE_SCAN_EXTRA_DATA_STRING)) {
        val scanData = intent.getStringExtra(DWInterface.DATAWEDGE_SCAN_EXTRA_DATA_STRING)
        val symbology = intent.getStringExtra(DWInterface.DATAWEDGE_SCAN_EXTRA_LABEL_TYPE)
        val date = Calendar.getInstance().time
        val df = SimpleDateFormat("dd/MM/yyyy HH:mm:ss")
        val dateTimeString = df.format(date)
        barcodeScannedEvent.onBarcodeScanEvent(scanData,symbology,dateTimeString)

    }
}
}

В моем файле ManiFest;

  <activity
        android:name=".view.activities.ViewPagerActivity"
        android:launchMode="singleTop"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateHidden">

        <intent-filter>
            <action android:name="app.example.dataWedge" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

    </activity>

Поскольку в моем профиле нет связанных приложений, если я просканирую что-либо, это не повлияет. Итак, я попытался добавить свой пакет вручную, после чего был вызван onNewIntent. Этот фрагмент кода DataWedge Functionality взят из github ref :: DataWedgeKotlin. Приложил скриншот и использую устройство Zebra TC25.

введите описание изображения здесь


person nethra gowda    schedule 23.07.2020    source источник


Ответы (1)


Это похоже на мой образец? :)

Эта строка:

appConfig.putString("PACKAGE_NAME", BuildConfig.APPLICATION_ID)

Должно быть:

appConfig.putString("PACKAGE_NAME", context.packageName)

person Darryn Campbell    schedule 23.07.2020
comment
Да, я пробовал то же самое, но не работает. Но пример кода, над которым я работал, по-прежнему отлично работает, я не знаю, что мне здесь не хватает. - person nethra gowda; 23.07.2020
comment
Мы пробовали TC57, сначала он работал, а затем после двух трех трейлов даже он перестал работать, но позже мы перезапустили TC57, теперь он работает. Для устройств TC25 все еще не работает - person nethra gowda; 23.07.2020
comment
В вашем примере кода у вас есть одно действие, в котором вы установили фильтры намерений и средство запуска, которые, кстати, отлично работают. Но для меня моя пусковая установка - это другое действие, а активность моего сканера - другая. - person nethra gowda; 23.07.2020
comment
У вас есть: const val PROFILE_INTENT_ACTION = BuildConfig.APPLICATION_ID Ваш фильтр намерений: ‹action android: name = app.example.dataWedge /› Эти значения должны быть одинаковыми, не так ли? - person Darryn Campbell; 23.07.2020
comment
Да, я изменил действие фильтра намерений, оно такое же, как и в моем файле манифеста. - person nethra gowda; 23.07.2020
comment
Проблема возникла в самом приложении DataWedge. Я выяснил и решил проблему. Большое спасибо - person nethra gowda; 23.07.2020