Zebra DataWedge API - obsługa Intent do skonfigurowania profili

0

Witam,

potrzebuje nakierowania co robię źle i czy w ogóle po stronie Fluttera jest to możliwe.
DataWedge API Documentation

Skorzystałem z biblioteki android_intent_plus i zrobiłem dla testów

floatingActionButton: FloatingActionButton(
  onPressed: () async {
    AndroidIntent intent = const AndroidIntent(
      action: 'com.symbol.datawedge.api.ACTION',
      arguments: <String, dynamic>{
        'com.symbol.datawedge.api.SWITCH_TO_PROFILE': "aztdemo2",
      },
    );
    await intent.launch();
  },
),

Ale dostaje błędy

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, No Activity found to handle Intent { act=com.symbol.datawedge.api.ACTION (has extras) }, null, android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.symbol.datawedge.api.ACTION (has extras) }

Dokumentacja zakłada, że piszę w Javie na Androida. Czy to Flutter mnie bloku z działaniem?

0

Nie wiem co ma Flutter do tego. Istnieje takie activity? Intent filter skonfigurowany w android manifest? A w Javie jak by to miało działać? A tak w ogóle, to nie lepiej zacząć tu? https://pub.dev/packages/flutter_datawedge

0

Piszę we Flutterze, nie wiem jak ma działać w Javie. Dodałem link z dokumentacją.

https://pub.dev/packages/flutter_datawedge - to daje tylko możliwość nasłuchiwania czytania kodów. Ja chce mieć możliwości zmiany konfiguracji w profilu. W kodzie, który załączyłem jest przykład wywołania SWITCH_TO_PROFILE.

W dokumentacji nie znalazłem żadnej konfiguracji manifestu. Wszedłem w przykład i wszędzie był ten sam kod różniący się tylko parametrami.

Intent i = new Intent(); 
i.setAction("com.symbol.datawedge.api.ACTION"); 
i.putExtra(EXTRA_DATA, "<parameter>"); 
0

Te com.symbol.datawedge.api.ACTION musi skądś się brać. Skonfigurowałeš wszystko tak jak każą? Co do konfiguracji manifestu, to niekoniecznie musisz to jawnie robić, biblioteka może to robić sama przez merged manifest. Spróbuj najpierw odpalić to w Javie/Kotlinie i zobacz czy działa

0

te com.symbol.datawedge.api.ACTION musi skądś się brać.

Stąd się bierze -> https://techdocs.zebra.com/datawedge/8-2/guide/api/switchtoprofile/. Wziąłem po prostu pierwszy lepszy przykład, czegokolwiek, aby zobaczyć czy to zadziała na Flutterze.

Jedyne co jest konfigurowane w manifeście, wzięte z przykładu https://github.com/darryncampbell/DataWedge-GettingStarted-Samples/blob/master/Kotlin/app/src/main/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.darryncampbell.dwgettingstartedkotlin">

    <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=".MainActivity"
            android:launchMode="singleTop">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.darryncampbell.datawedge.kotlin.ACTION" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Ale ja kompletnie nic z tego nie rozumiem, ponieważ w przypadku Fluttera, w manifeście, muszę ustawiać tylko uprawnienia. Nie znam Javy, nie znam Kotlina, nie wiem na jakiej zasadzie działa Intent. Wiem tylko tyle, że nie mogę sobie tego skopiować i wkleić do siebie, bo nie zadziała.

<intent-filter>
  <action android:name="com.darryncampbell.datawedge.kotlin.ACTION" />
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
0

Ten intent filter nie bez powodu tam jest. Czy to zadziała tego nie wiem, oczywiście musisz tam wstawić swoją nazwę pakietu. Możliwe, że będziesz musiał jednak to wszystko napisać natywnie, jako wtyczkę do Fluttera

Jak to działa opisano w dokumentacji: https://developer.android.com/guide/components/intents-filters

0

jak pomoże Ci coś z Kotlina :
w manifest mam tylko coś takiego :
<receiver android:name=".DWReceiver" android:enabled="true" android:exported="true" />

przykładowo Intent listą towarów :
private lateinit var connectionBroadcastReceiver: DWReceiver;

w onCreate :

        connectionBroadcastReceiver = object : DWReceiver() {
            override fun broadcastResult(kod: String) {
                _kod.value=kod;
                handler?.sendEmptyMessage(5);

            }
        }
        rejestrujReciver();
   fun rejestrujReciver() {
        if (!connectionBroadcastReceiver.register) {

            //  Register broadcast receiver to listen for responses from DW API
            val intentFilter = IntentFilter()
            intentFilter.addAction(DWInterface.DATAWEDGE_SCAN_EXTRA_DATA_STRING);
            intentFilter.addAction(MainActivity.PROFILE_INTENT_ACTION);
            registerReceiver(connectionBroadcastReceiver, intentFilter)
            connectionBroadcastReceiver.register = true;
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        if (connectionBroadcastReceiver.register) {
            unregisterReceiver(connectionBroadcastReceiver)
            connectionBroadcastReceiver.register = false;
        }        
        client.dispose();
    }        

taką klase mam :

package com.netsoft.magazynxl

import android.content.Context
import android.content.Intent
import android.os.Bundle

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

i taką :

package com.netsoft.magazynxl

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent



abstract class DWReceiver : BroadcastReceiver() {
    var register:Boolean=false;
    override fun onReceive(context: Context, intent: Intent) {
        //  This method is called when the BroadcastReceiver is receiving an Intent broadcast.
        //  Notify registered observers
//        ObservableObject.instance.updateValue(intent)
        if (intent.hasExtra(DWInterface.DATAWEDGE_SCAN_EXTRA_DATA_STRING))
            {
                var scanData = intent.getStringExtra(DWInterface.DATAWEDGE_SCAN_EXTRA_DATA_STRING)
                broadcastResult(scanData.toString());

            }
        if (intent.hasExtra(DWInterface.DATAWEDGE_EXTRA_RESULT_INFO ))
        {
        }


    }
    protected abstract fun broadcastResult(kod:String)
} 

a tak tworzę własny profil

    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(this, DWInterface.DATAWEDGE_SEND_CREATE_PROFILE,
            MainActivity.PROFILE_NAME
        )
        val profileConfig = Bundle()
        profileConfig.putString("PROFILE_NAME", MainActivity.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()
        barcodeProps.putString("scanner_input_enabled", "true")
        barcodeConfig.putBundle("PARAM_LIST", barcodeProps)
        profileConfig.putBundle("PLUGIN_CONFIG", barcodeConfig)
        val appConfig = Bundle()
        appConfig.putString("PACKAGE_NAME", packageName)      //  Associate the profile with this app
        appConfig.putStringArray("ACTIVITY_LIST", arrayOf("*"))
        profileConfig.putParcelableArray("APP_LIST", arrayOf(appConfig))
        dwInterface.sendCommandBundle(this, 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", MainActivity.PROFILE_INTENT_ACTION)
        intentProps.putString("intent_delivery", MainActivity.PROFILE_INTENT_START_ACTIVITY) 
        intentConfig.putBundle("PARAM_LIST", intentProps)
        profileConfig.putBundle("PLUGIN_CONFIG", intentConfig)
        dwInterface.sendCommandBundle(this, DWInterface.DATAWEDGE_SEND_SET_CONFIG, profileConfig)
        profileConfig.remove("PLUGIN_CONFIG")
        val bundleKSOutConfig = Bundle()
        bundleKSOutConfig.putString("PLUGIN_NAME", "KEYSTROKE")
        bundleKSOutConfig.putString("RESET_CONFIG", "false")
        val bundleKSParams = Bundle()
        bundleKSParams.putString("keystroke_output_enabled", "false")
        bundleKSOutConfig.putBundle("PARAM_LIST", bundleKSParams)
        profileConfig.putBundle("PLUGIN_CONFIG", bundleKSOutConfig)
        dwInterface.sendCommandBundle(this, DWInterface.DATAWEDGE_SEND_SET_CONFIG, profileConfig)
    }
Sorry że troche bałaganu ale może się przyda

1 użytkowników online, w tym zalogowanych: 0, gości: 1