import { Injectable } from '@angular/core' ; import { Events } from '../../services/events' ; import { Platform } from '@ionic/angular' ; @ Injectable ( ) export class BarcodeProvider { private requestResultCodes = "false" ; constructor ( public events , private platform ) { this . platform . ready ( ) . then ( ( readySource ) => { let constructorInstance = this ; ( < any > window ) . plugins . intentShim . registerBroadcastReceiver ( { filterActions : [ 'com.zebra.ionicdemo.ACTION' , 'com.symbol.datawedge.api.RESULT_ACTION' ] , filterCategories : [ 'android.intent.category.DEFAULT' ] } , function ( intent ) { console . log ( 'Received Intent: ' + JSON . stringify ( intent . extras ) ) ; if ( intent . extras . hasOwnProperty ( 'RESULT_INFO' ) ) { let commandResult = intent . extras . RESULT + " (" + intent . extras . COMMAND . substring ( intent . extras . COMMAND . lastIndexOf ( '.' ) + 1 , intent . extras . COMMAND . length ) + ")" ; 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' ) ) { 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' ) ) { 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' ) ) { constructorInstance . events . publish ( 'data:scan' , { scanData : intent , time : new Date ( ) . toLocaleTimeString ( ) } ) ; } } ) ; } ) ; } requestResult ( requestCodes ) { this . requestResultCodes = "" + requestCodes ; } sendCommand ( extraName , 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 ( ) { } ) ; } }