1

私は 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)

    }
}
}

私のマニフェストファイルで;

  <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 デバイスを使用しています。

ここに画像の説明を入力

4

1 に答える 1