darryncampbell / darryncampbell-cordova-plugin-intent

General purpose intent shim layer for cordova appliations on Android. Handles various techniques for sending and receiving intents.
MIT License
86 stars 130 forks source link

Using plugin to scan a barcone on Zebra TC57 #126

Closed hiryuken closed 3 years ago

hiryuken commented 3 years ago

Hello @darryncampbell ,

I am trying to use the plugin on a TC57 device. Actually I am having troubles even just running the test application on that device and it seems that I can send the command to the zebra to start scanning, I can even get some event back, but I don't get any data but if the IR is fired and is reading something.

I Can also tell you that I can enumerate the scanners, but it seems i can't set the profile I want.

I wonder if you can give me any advice on how to let it work

I'll attach the service I am using (mostly the same from your example).

Thanks for your help,

Alessandro

import { BehaviorSubject } from 'rxjs';
import { Injectable } from '@angular/core';
import { Platform } from 'ionic-angular';
import { Events } from 'ionic-angular/util/events';@Injectable()

export class BarcodeProvider {
  private requestResultCodes = "false";

  constructor(public events: Events, private platform: Platform) {
    this.platform.ready().then((readySource) => {
      let constructorInstance = this;
      (<any>window).plugins.intentShim.registerBroadcastReceiver({
        filterActions: [
          'com.zebra.mycart.ACTION',           //  Response from scan (needs to match value in output plugin)
          'com.symbol.datawedge.api.ACTION',
          'com.symbol.datawedge.api.RESULT_ACTION'//  Response from DataWedge service (as defined by API)
        ],
        filterCategories: [
          'android.intent.category.DEFAULT'
        ]
      },
        function (intent) {
          //  Broadcast received
          console.log('my intent: ' + JSON.stringify(intent));
          console.log('Received Intent: ' + JSON.stringify(intent.extras));
          //  Emit a separate event for the result associated with this scan.  This will only be present in response to
          //  API calls which included a SEND_RESULT extra
          if (intent.extras.hasOwnProperty('RESULT_INFO')) {
            let commandResult = intent.extras.RESULT + " (" +
              intent.extras.COMMAND.substring(intent.extras.COMMAND.lastIndexOf('.') + 1, intent.extras.COMMAND.length) + ")";  // + JSON.stringify(intent.extras.RESULT_INFO);
            constructorInstance.events.publish('data:commandResult', commandResult.toLowerCase());
          }

          if (intent.extras.hasOwnProperty('com.symbol.datawedge.api.RESULT_GET_VERSION_INFO')) {
            var versionInfo = intent.extras['com.symbol.datawedge.api.RESULT_GET_VERSION_INFO'];
            console.log('Version Info: ' + JSON.stringify(versionInfo));
            let datawedgeVersion = versionInfo['DATAWEDGE'];
            console.log("Datawedge version: " + datawedgeVersion);
            if (datawedgeVersion >= "6.3")
              constructorInstance.events.publish('status:dw63ApisAvailable', true);
            if (datawedgeVersion >= "6.4")
              constructorInstance.events.publish('status:dw64ApisAvailable', true);
            if (datawedgeVersion >= "6.5")
              constructorInstance.events.publish('status:dw65ApisAvailable', true);
          }
          else if (intent.extras.hasOwnProperty('com.symbol.datawedge.api.RESULT_ENUMERATE_SCANNERS')) {
            //  Return from our request to enumerate the available scanners
            let enumeratedScanners = intent.extras['com.symbol.datawedge.api.RESULT_ENUMERATE_SCANNERS'];
            constructorInstance.events.publish('data:enumeratedScanners', enumeratedScanners);
          }

          else if (intent.extras.hasOwnProperty('com.symbol.datawedge.api.RESULT_GET_ACTIVE_PROFILE')) {
            //  Return from our request to obtain the active profile
            let activeProfile = intent.extras['com.symbol.datawedge.api.RESULT_GET_ACTIVE_PROFILE'];
            constructorInstance.events.publish('data:activeProfile', activeProfile);
          }

          else if (!intent.extras.hasOwnProperty('RESULT_INFO')) {
            //  A barcode has been scanned
            console.log('data:scan', intent)
            constructorInstance.events.publish('data:scan', {scanData: intent, time: new Date().toLocaleTimeString()});
          }
        }
      );
    });
  }

  requestResult(requestCodes: boolean) {
    this.requestResultCodes = "" + requestCodes;
  }

  sendCommand(extraName: string, extraValue) {
    console.log("Sending Command: " + extraName + ", " + JSON.stringify(extraValue));
    (<any>window).plugins.intentShim.sendBroadcast({
      action: 'com.symbol.datawedge.api.ACTION',
      extras: {
        [extraName]: extraValue,
        "SEND_RESULT": this.requestResultCodes
      }
    },
      function () { },  
      function () { }  
    );
  }
}
darryncampbell commented 3 years ago

Hi,

hiryuken commented 3 years ago

Hello Darryn and thank you very much,

I am trying to run this https://github.com/ZebraDevs/DataWedge-Ionic-Demo

DataWedge version: 8.0.37 Scanning Framework version: 23.1.13.0

The DataWedge profile ZebraIonicDemo is being created but is not used by the app (in the app the active profile is always Profile Default0).

I did try to restore the DataWedge and launching the app, but i have the same results.

Thank you for your help.

darryncampbell commented 3 years ago

Hi, strange, can you please confirm that the 'associated applications' in the ZebraIonicDemo profile points to the demo application? That version of DataWedge should be sufficient to run the demo

hiryuken commented 3 years ago

Hello, yes I can post you here some pics from the Zebra, it seems that the profile points to the demo application. 881857cb-b4b1-4924-8e8f-cc20ff94c209 e6a9c7d0-e4d1-4e4f-9e27-596df65a6d78 adba1f2c-6c69-4d27-b5cc-b0499605ce6f

darryncampbell commented 3 years ago

I tried changing the language of my TC52 in case this was related to language but it still works fine for me. I can install the ZebraIonicDemo and the Active Profile shows as "ZebraIonicDemo" rather than "Profile0 (default)" which is what you see.

I do have a TC57 in my drawer. What BSP are you running? Settings --> About Phone --> Build number. I will then test it on a device configured exactly the same as yours.

hiryuken commented 3 years ago

@darryncampbell Thank you very much, reading your answers we could find out what was going wrong. Actually it was just my mistake in giving the wrong name to the ionic App. The app ID wasnt matching properly the DataWedge profile so it wouldn't "connect" and the events were missing. I could change the App ID and recompiled the app and now it works perfectly! Thank you very much for your precious help!