【问题标题】:Profile is created but there are no apps associated in DataWedge Zebra TC25配置文件已创建,但 DataWedge Zebra TC25 中没有关联的应用程序
【发布时间】:2020-07-23 12:50:55
【问题描述】:

我正在使用 Zebra TC25 设备,尝试以编程方式使用 DataWedge API 创建配置文件。配置文件已创建,我尝试扫描条形码但没有任何反应因此我检查了我的 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 功能来自这个 github ref::DataWedgeKotlin。附上截图,我正在使用 Zebra TC25 设备。

【问题讨论】:

    标签: android barcode-scanner intentfilter datawedge


    【解决方案1】:

    这看起来像我的样本? :)

    这一行:

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

    应该是:

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

    【讨论】:

    • 是的,我尝试过同样的方法仍然无法正常工作。但是我处理的示例代码仍然可以完美运行我不知道我在这里缺少什么。
    • 我们在 TC57 上进行了尝试,最初它可以工作,然后经过两个三个路径甚至停止工作,但后来我们在 TC57 上重新启动它现在可以工作了。对于 TC25 设备,它仍然无法正常工作
    • 在您的示例代码中,您有一个活动,您在其中设置了意图过滤器和启动器,顺便说一句工作正常。但对我来说,我的启动器是不同的活动,我的扫描仪活动是不同的。
    • 你有: const val PROFILE_INTENT_ACTION = BuildConfig.APPLICATION_ID 你的意图过滤器是: 这些值应该是一样的,是吗?跨度>
    • DataWedge 应用程序本身存在问题,我已经发现并解决了该问题。非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 2018-10-26
    • 1970-01-01
    • 1970-01-01
    • 2018-05-29
    • 2022-12-29
    • 1970-01-01
    相关资源
    最近更新 更多