DataMemorLogic10 Intent Wedge

Hello @Donato_Cataldo,

First of all, I want to thank you about article you shared about IntentWedge via flutter. That is incredibly fast even with the longest barcodes. I have only one struggle. When Intent wedge feature is not enabled by user we can not use the IntentWedge. So I needed to check whether IntentWedge feature is enabled or not at the beginning of the app and if it is not enabled, I want to redirect the user to related settings and open it. Can you explain to me how to achieve this one?

Have a good Day!

Mehmet Akif SAYRIM
Flutter Developer

Hello @Mehmet_Akif_SAYRIM,

Welcome to our forum, glad to have you here.

I’ll see if there is anything I can answer, if I miss something Donato can help fill in the gaps.

You can use our SDK to do all of this, no need to send the user to a page in the settings.
You will want to check if the normal keyboard wedge is enabled and disable that so that the barcode data is not typed on screen.
Then check if the intent wedge is disabled and enable it if needed.

Here some links to our SDK documentation:

https://datalogic.github.io/android-sdk-docs/reference/com/datalogic/decode/configuration/KeyboardWedge.html

https://datalogic.github.io/android-sdk-docs/reference/com/datalogic/decode/configuration/IntentWedge.html

Also, here is a link to some example apps written in Kotlin and Java.
There is a specific example app, DecodeConfig, which covers adjusting the decode configuration.
The example doesn’t cover adjusting the wedge but similar settings.

Drew Hugentobler
L3 Mobile Computer Specialist Support Engineer

1 Like

Hello @Mehmet_Akif_SAYRIM ,
I wanted to give you exactly the same answer as @Drew_Hugentobler (Thank you Drew).
I hope it is useful for you.

Donato Cataldo
L3 Mobile Computer Specialist Support Engineer

1 Like

Thanks for your quick replies @Donato_Cataldo and @Drew_Hugentobler. My aim was if you not manually open intent wedge feature from android settings, It is not working(as it should be). Just to be sure that each time I open my app I want to check that intent wedge feature is enabled programmatically or not . Cause somehow, it can be disabled by end user and they may complain about it is not working :D. I tried many options(SDK documentations included.) and could not find any solution for this. My approach to this topic might be wrong. What do you say about this?

Hello @Mehmet_Akif_SAYRIM,

It is hard to know for sure what could be causing your issue.
This is the first report we have heard of this issue.
One way we could assist you is to review your code.
The easiest way would be for you to edit the decodeConfig example we provide.
Add the code needed to accomplish your goal and verify it is not working.
Then send us that code and we can see if there is something you are missing or if it is a defect in our SDK.

Drew Hugentobler
L3 Mobile Computer Specialist Engineer

Hello @Drew_Hugentobler ,

I’m actually trying to say that I want to check intent wedge is enabled or not in android OS settings.I’m sharing the photo of it. In my flutter app, I want to check exactly this setting whether it is enabled or disabled. If This setting is disabled somehow, I want to let user knows that is actually intent wedge feature is disabled by settings. I want to show some sort of pop up and navigate the user to related settings from the app. Hope I can be more clear.

Have a good day!

Hello @Mehmet_Akif_SAYRIM,

Thank you for your patience while we assist you with this issue.
I fully understand what you are trying to do.

I’m actually trying to say that I want to check intent wedge is enabled or not in android OS settings.

The intent wedge is disabled by default, there are several things that can revert this setting to default. Ideally you would fix whatever is disabling this setting. But you can do what you are describing.

I’m sharing the photo of it. In my flutter app, I want to check exactly this setting whether it is enabled or disabled.

Check the setting enable intent wedge, I understand.

If This setting is disabled somehow, I want to let user knows that is actually intent wedge feature is disabled by settings.

You can check and change this setting programmatically. The user does not need to know if it is on or not.

I want to show some sort of pop up and navigate the user to related settings from the app. Hope I can be more clear.

You could do this, but we do not offer a way to send someone to a particular part of our settings. We don’t offer this feature because we allow you the developer to change the settings without user input.

Here is an example of how to do this with Kotlin.

// ©2023 Datalogic S.p.A. and/or its affiliates. All rights reserved.

import com.datalogic.decode.BarcodeManager
import com.datalogic.decode.configuration.ScannerProperties
import com.datalogic.device.configuration.ConfigException
import com.datalogic.device.ErrorManager

import android.os.Bundle
import android.app.Activity
import android.util.Log

import com.datalogic.samples.R

class DecodeConfiguration : Activity() {

    // Constant for log messages.
    private val LOGTAG = javaClass.name

    private var manager: BarcodeManager? = null
    private var configuration: ScannerProperties? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Create a BarcodeManager.
        manager = BarcodeManager()

        // Pass it to ScannerProperties class.
        // ScannerProperties cannot be instantiated directly, instead call edit.
        configuration = ScannerProperties.edit(manager)

        // Now we can change some Scanner/Device configuration parameters.
        // These values are not applied, as long as the store method is not called.

        configuration!!.keyboardWedge.enable.set(false)
        configuration!!.intentWedge.enable.set(true)

        // Change the IntentWedge action and category to specific ones.
        configuration!!.intentWedge.action.set("com.datalogic.examples.decode_action")
        configuration!!.intentWedge.category.set("com.datalogic.examples.decode_category")

        // From here on, we would like to get a return value instead of an exception in case of error.
        ErrorManager.enableExceptions(false)

        // Now we are ready to store our settings changes.
        // Second parameter set to true saves configuration in a permanent way.
        // After boot, settings will be still valid.
        val errorCode = configuration!!.store(manager, true)

        // Check the return value.
        if (errorCode != ConfigException.SUCCESS) {
            Log.e(LOGTAG, "Error during store", ErrorManager.getLastError())
        }
    }
}
1 Like

Hello @Drew_Hugentobler ,

That is a great answer. This is exactly what I needed. Thanks for your quick and awesome response.

Have a nice day!

1 Like

Hello @Donato_Cataldo @Drew_Hugentobler ,

I added Datalogic memor SDK to build.gradle and it is working fine in debug mode at flutter. But when I try in release mode it says asynchronous suspension error. Do you have any idea that what possibly cause this problem?
buildGradle
logs

Hello @Mehmet_Akif_SAYRIM,

I have not run into that exact error before but I see a few differences in your gradle vs our example.
Here are our Gradle files from our example.

Our settings.gradle

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}
rootProject.name = "My Application"
include ':app'

Our build.gradle (:app)

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'com.datalogic.myapplication'
    compileSdk 33

    defaultConfig {
        applicationId "com.datalogic.myapplication"
        minSdk 28
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation 'com.github.datalogic:datalogic-android-sdk:1.32'
    implementation 'androidx.core:core-ktx:1.9.0'
    implementation 'androidx.appcompat:appcompat:1.6.0'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

Drew Hugentobler
L3 Mobile Computer Specialist Support Engineer

Hello @Drew_Hugentobler,

I tried couple things but no luck. It is working in debug mode but not working in release mode. I sharing my build Gradle files and my mainActivity codes. Hope You can understand what I’m missing :slight_smile:

BuildGradle(app level)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
 
    compileSdkVersion 33

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.mpsmobile.assistant"
        minSdkVersion 21
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true

    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'com.github.datalogic:datalogic-android-sdk:1.32'

}

BuildGradle

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

MainActivity.kt

package com.mpsmobile.assistant

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.widget.Toast
import androidx.annotation.NonNull
import com.datalogic.decode.BarcodeManager
import com.datalogic.decode.configuration.ScannerProperties
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

class MainActivity: FlutterActivity() {

    private val ACTION_BROADCAST_RECEIVER =  "com.datalogic.decodewedge.decode_action"
    private val CATEGORY_BROADCAST_RECEIVER = "com.datalogic.decodewedge.decode_category"
    private val EXTRA_DATA_STRING = "com.datalogic.decode.intentwedge.barcode_string"
    private val EVENT_CHANNEL_BARCODE_INTENT = "app.channel.event.barcode_intent"
   private var receiver: BroadcastReceiver? = null
    private var filter: IntentFilter? = null
    private val CHANNEL = "datalogic/configuration"

    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)





        EventChannel(flutterEngine.dartExecutor.binaryMessenger, EVENT_CHANNEL_BARCODE_INTENT).setStreamHandler(
            object : EventChannel.StreamHandler {

                override fun onListen(args: Any?, events: EventChannel.EventSink) {



                        receiver = BarcodeIntentReceiver(events)

                        filter = IntentFilter()

                        filter!!.addAction(ACTION_BROADCAST_RECEIVER)
                        filter!!.addCategory(CATEGORY_BROADCAST_RECEIVER)

                        registerReceiver(receiver, filter)


                }

                override fun onCancel(args: Any?) {
                    //Log.i(LOGTAG, "EVENT_CHANNEL_BARCODE_INTENT has been canceled")
                }
            }
        )
        MethodChannel(
            flutterEngine.dartExecutor.binaryMessenger,
            CHANNEL
        ).setMethodCallHandler { call, result ->
            when {
                call.method.equals("enableIntentWedge") -> {


                    enableIntentWedge(call, result)



                }
            }
        }
    }
    private fun BarcodeIntentReceiver(events: EventChannel.EventSink?) : BroadcastReceiver? {
        return object : BroadcastReceiver() {
            override fun onReceive(context: Context, wedgeIntent: Intent) {
                //Log.i(LOGTAG, "received" + wedgeIntent.action)

                val action = wedgeIntent.action

                if (action == ACTION_BROADCAST_RECEIVER) {

            

                    events?.success(wedgeIntent.getStringExtra(EXTRA_DATA_STRING))

                    //Log.i(LOGTAG, "Decoding Broadcast Received")
                }
            }
        }
    }
    private fun enableIntentWedge(call: MethodCall, result :MethodChannel.Result){
        var managerx: BarcodeManager? = null
        var configurationx: ScannerProperties? = null
        var alreadyEnabled=false;
        var isEnabled= call.arguments<Boolean>()?:false;
        println(isEnabled)

        // Create a BarcodeManager.

        managerx = BarcodeManager()

        // Pass it to ScannerProperties class.w
        // ScannerProperties cannot be instantiated directly, instead call edit.

        configurationx = ScannerProperties.edit(managerx)



       alreadyEnabled= configurationx.intentWedge.enable.get()
        println("AlreadyEnabled: $alreadyEnabled")
        // Now we can change some Scanner/Device configuration parameters.
        // These values are not applied, as long as the store method is not called.
        // if keyboard wedge is enabled, intent wedge should be disabled.
      if(!alreadyEnabled) {

           configurationx!!.keyboardWedge.enable.set(isEnabled?.not() ?: false)
           configurationx!!.intentWedge.enable.set(isEnabled)
          // Change the IntentWedge action and category to specific ones.
          configurationx!!.intentWedge.action.set(ACTION_BROADCAST_RECEIVER)
          configurationx!!.intentWedge.category.set(CATEGORY_BROADCAST_RECEIVER)

          // Now we are ready to store our settings changes.
          // Second parameter set to true saves configuration in a permanent way.
          // After boot, settings will be still valid.
           configurationx!!.store(managerx, true)
           alreadyEnabled= configurationx.intentWedge.enable.get()
          if(alreadyEnabled){
              Toast.makeText(applicationContext,"Intent Wedge feature is enabled" ,Toast.LENGTH_SHORT)
          }
          else {
              Toast.makeText(applicationContext,"Keyboard Wedge feature is enabled" ,Toast.LENGTH_SHORT)
          }

       }


        }
    }

Flutter Invoke Method

 static Future<void> enableIntentWedge() async {
    var platform = const MethodChannel("datalogic/configuration");
    try {
      await platform.invokeMethod("enableIntentWedge", true);
    } catch (e) {
      print("error$e");
    }
  }

This is the error I get in release mode.
release build error

Hi @Mehmet_Akif_SAYRIM,

is it possible for you to share us the whole Project with the source code so we can do some compilation tests?
I suggest you fill out the form available at this link to get in touch with Technical Support and share your Project.

Donato Cataldo
L3 Mobile Computer Support Engineer

Hello @Donato_Cataldo ,

I can not share entire project with you due to Company privacy rules. I already did a template project and reproduced the error again. I will share with techTeam. Thanks for your help.

Have a good day!