首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在斑马条形码扫描仪上使用DataWedge进行多个活动在Kotlin中不起作用

在斑马条形码扫描仪上使用DataWedge进行多个活动在Kotlin中不起作用
EN

Stack Overflow用户
提问于 2022-01-07 18:16:28
回答 1查看 659关注 0票数 0

我正在开发一个应用程序斑马条形码扫描仪在科特林,我需要扫描条码在多个活动。此时,我正在尝试使用DataWedge。我遵循了本教程:https://github.com/darryncampbell/DataWedge-GettingStarted-Samples,这是一个伟大的活动。但问题在于多项活动。我的想法是在主活动中创建DatWedge配置文件,然后我需要扫描第二和第三个活动中的条形码(第三个活动与第二个活动相同)。有可能吗?当我按下硬按钮时,设备发出嗡嗡声,但TextView中没有显示任何东西,甚至日志也不起作用。

我只是使用硬触发器,所以它不需要使用软扫描。我是MainActivity。DWUtilities对象与教程中的对象相同。

代码语言:javascript
复制
override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        DWUtilities.CreateDWProfile(this)
        val btnScan = findViewById<Button>(R.id.btnScan)
        btnScan.setOnClickListener {
            val intent = Intent(this, SecondActivity::class.java)
            startActivity(intent)
        }
    }

我是SecondActivity。活动只包含按钮和textView。

代码语言:javascript
复制
override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_second)
        val btnSec = findViewById<Button>(R.id.btnScanSecond)
        btnSec.setOnClickListener {
            val intent = Intent(this, ThirdActivity::class.java)
            startActivity(intent)
        }
    }
    override fun onNewIntent(intentSken: Intent) {
        super.onNewIntent(intentSken)
        displayScanResult(intentSken)
    }
    private fun displayScanResult(scanIntent: Intent) {
        val decodedSource =
            scanIntent.getStringExtra(resources.getString(R.string.datawedge_intent_key_source))
        val decodedData =
            scanIntent.getStringExtra(resources.getString(R.string.datawedge_intent_key_data))
        val decodedLabelType =            scanIntent.getStringExtra(resources.getString(R.string.datawedge_intent_key_label_type))
        val scan = "$decodedData [$decodedLabelType]\n\n"
        val output = findViewById<TextView>(R.id.txtOutputSecond)        
        output.text = scan + output.text
        Log.d("Scan", "$scan")
    }

这很明显。实际上,我认为这个清单应该有问题,但我不确定。

代码语言:javascript
复制
<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".ThirdActivity"
            android:exported="false"
            android:launchMode="singleTop">
            <intent-filter>
                <action android:name="com.darryncampbell.datawedge.kotlin.ACTION" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".SecondActivity"
            android:exported="false"
            android:launchMode="singleTop">
            <intent-filter>
                <action android:name="com.darryncampbell.datawedge.kotlin.ACTION" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
代码语言:javascript
复制
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-17 07:42:11

在您发布的教程中,这一行:https://github.com/darryncampbell/DataWedge-GettingStarted-Samples/blob/master/Kotlin/app/src/main/java/com/darryncampbell/dwgettingstartedkotlin/DWUtilities.kt#L40将使DataWedge配置文件应用于应用程序中的所有活动。您可以在这里指定单个活动,仅将设置应用于单个活动com.darryncampbell.dwgettingstartedkotlin.MainActivity。然后您可以定义多个DataWedge配置文件,这样应用程序中的每个活动都可以使用自己的设置拥有自己的配置文件。

另一个考虑是如何配置意图输出插件,教程将其作为startActivity发送。您可以在每个活动中使用不同的意图筛选器,每一个都注册不同的操作,或者您可以更改配置文件以调用sendBroadcast,并在每个活动中都有一个广播接收器来接收扫描。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70625523

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档