GSW Browser - Example Code List

Below are the featured live demos currently avaliable.
Each example will also have the JavaScript code used to make the demo functional to assist in adding it to other projects.


You must be using the GSW ConnectBot Enterprise Browser for the live demos to work.



Scanner Demo Code


GSW Scanner

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};
GSW.Tests.onDeviceReady = function() {
  // Cordova is now initialized. Have fun!
  console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
  navigator.gswscanner.initialize(function(data) {
    console.log('initialize OK');
    document.getElementById('scan_now').addEventListener("touchstart", GSW.Tests.scanPressed);
    document.getElementById('scan_now').addEventListener("touchend", GSW.Tests.scanReleased);
    document.getElementById('scan_now').addEventListener("touchmove", GSW.Tests.scanReleased);
    document.getElementById('scan_now').addEventListener("touchcancel", GSW.Tests.scanReleased);
    GSW.Tests.disable();
    document.getElementById("interface").innerHTML = navigator.gswscanner.api.bold();
  }, function(error) {
      if (error == "Scanner api is unavailable on this device"){
       let notice = document.getElementById("noticeContainer");
       notice.style.display = "block";
       document.getElementById("error").innerHTML = "This device does not have a compatible scanner present, and is not compatible with this demo."
    } else if(error.indexOf('scanner decode service is unavailable on this device') != -1){
      let notice = document.getElementById("noticeContainer");
      notice.style.display = "block";
      document.getElementById("error").innerHTML = "This device was not manufactured by a supported manufacturer and is not compatible with this demo."
    }  
    else console.log('Initialize error occured: ' + error);
  });
}

GSW.Tests.scanPressed = function() {
  console.log("scanPressed");
              navigator.gswscanner.enableTrigger(function(result) {
        navigator.gswscanner.softwareTriggerStart(function(result) {
          document.getElementById('userid').value = result.data;
          document.getElementById('character_set').value = result.character_set;
          document.getElementById('code_id').value = result.code_id;
          document.getElementById('aim_id').value = result.aim_id;
          document.getElementById('timestamp').value = result.timestamp;
          console.log('Software scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
        }, function(error) {
          console.log('Error occured: ' + error);
        });
              }, function(error) {
    console.log('Unable to enable trigger: ' + error);
  })
}

GSW.Tests.scanReleased = function() {
  console.log("scanReleased");
    navigator.gswscanner.disableTrigger(function(result) {
      navigator.gswscanner.softwareTriggerStop();
    }, function(error) {
      console.log('Unable to disable trigger: ' + error);
    })
}

  GSW.Tests.disable = function() {
    navigator.gswscanner.disableTrigger(function(result) {
      console.log('Trigger disabled');
    }, function(error) {
      console.log('Unable to disable trigger: ' + error);
    })
  }
document.addEventListener('gswscannerready', GSW.Tests.onDeviceReady, false);
            

GSW Scanner Listen

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
    // Cordova is now initialized. Have fun!
    console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
    navigator.gswscanner.initialize(function(data) {
        console.log('initialize OK');
        document.getElementById("interface").innerHTML = navigator.gswscanner.api.bold();
        navigator.gswscanner.listen(function(result) {
            document.getElementById('data').value = result.data;
            document.getElementById('character_set').value = result.character_set;
            document.getElementById('code_id').value = result.code_id;
            document.getElementById('aim_id').value = result.aim_id;
            document.getElementById('timestamp').value = result.timestamp;
            console.log('Scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
        }, function(error) {
            console.log('Unable to listen: ' + error);
        });
        var enabled = true;
        document.getElementById("enable_trigger").disabled = true;
        document.getElementById("disable_trigger").disabled = false;
        document.getElementById('enable_trigger').addEventListener("click", function() {
            navigator.gswscanner.enableTrigger(function(result) {
                enabled = true;
                document.getElementById("enable_trigger").disabled = true;
                document.getElementById("disable_trigger").disabled = false;
                console.log('Trigger enabled');
            }, function(error) {
                console.log('Unable to enable trigger: ' + error);
            })
        });
        document.getElementById('disable_trigger').addEventListener("click", function() {
            navigator.gswscanner.disableTrigger(function(result) {
                enabled = false
                document.getElementById("enable_trigger").disabled = false;
                document.getElementById("disable_trigger").disabled = true;
                console.log('Trigger disabled');
            }, function(error) {
                console.log('Unable to disable trigger: ' + error);
            })
        });
    }, function(error) {
        console.log('Initialize error occured: ' + error);
        document.getElementById("enable_trigger").disabled = true;
        document.getElementById("disable_trigger").disabled = true;
if (error == "Scanner api is unavailable on this device"){
 let notice = document.getElementById("noticeContainer");
 notice.style.display = "block";
 document.getElementById("error").innerHTML = "This device does not have a compatible scanner present, and is not compatible with this demo."
} else if(error.indexOf('scanner decode service is unavailable on this device') != -1){
let notice = document.getElementById("noticeContainer");
notice.style.display = "block";
document.getElementById("error").innerHTML = "This device was not manufactured by a supported manufacturer and is not compatible with this demo."
}  
else console.log('Initialize error occured: ' + error);
    });
}
document.addEventListener('gswscannerready', GSW.Tests.onDeviceReady, false);
            

GSW Scanner Field

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
  // Cordova is now initialized. Have fun!
  console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
  navigator.gswscanner.initialize(function(data) {
    console.log('initialize OK');
    document.getElementById('userid').addEventListener("focus", GSW.Tests.enable);
    document.getElementById('userid').addEventListener("blur", GSW.Tests.disable);
    GSW.Tests.disable();
    document.getElementById("interface").innerHTML = navigator.gswscanner.api.bold();
  }, function(error) {
      if (error == "Scanner api is unavailable on this device"){
       let notice = document.getElementById("noticeContainer");
       notice.style.display = "block";
       document.getElementById("error").innerHTML = "This device does not have a compatible scanner present, and is not compatible with this demo."
    } else if(error.indexOf('scanner decode service is unavailable on this device') != -1){
      let notice = document.getElementById("noticeContainer");
      notice.style.display = "block";
      document.getElementById("error").innerHTML = "This device was not manufactured by a supported manufacturer and is not compatible with this demo."
    }  
    else console.log('Initialize error occured: ' + error);
  });
}

GSW.Tests.enable = function(event) {
  console.log('enable');
  navigator.gswscanner.enableTrigger(function(result) {
    navigator.gswscanner.listen(function(result) {
      document.getElementById('userid').value = result.data;
      document.getElementById('character_set').value = result.character_set;
      document.getElementById('code_id').value = result.code_id;
      document.getElementById('aim_id').value = result.aim_id;
      document.getElementById('timestamp').value = result.timestamp;
      console.log('Scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
    }, function(error) {
      console.log('Error occured: ' + error);
    });
  },function(error) {
    console.log('Unable to enable trigger: ' + error);
  })
}

  GSW.Tests.disable = function() {
    navigator.gswscanner.disableTrigger(function(result) {
      console.log('Trigger disabled');
    }, function(error) {
      console.log('Unable to disable trigger: ' + error);
    })
  }

document.addEventListener('gswscannerready', GSW.Tests.onDeviceReady, false);
            

Honeywell Scanner

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};
GSW.Tests.onDeviceReady = function() {
  // Cordova is now initialized. Have fun!
  console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
  navigator.gswhoneywellscanner.initialize(function(data) {
    console.log('initialize OK');
    document.getElementById('scan_now').addEventListener("touchstart", GSW.Tests.scanPressed);
    document.getElementById('scan_now').addEventListener("touchend", GSW.Tests.scanReleased);
    document.getElementById('scan_now').addEventListener("touchmove", GSW.Tests.scanReleased);
    document.getElementById('scan_now').addEventListener("touchcancel", GSW.Tests.scanReleased);
    GSW.Tests.disable();
  }, function(error) {
    if(error == "Honeywell scanner decode service is unavailable on this device") {
      let notice = document.getElementById("noticeContainer");
      notice.style.display = "block";
      document.getElementById("error").innerHTML = "This device was not manufactured by Honeywell and is not compatible with this demo."
    } else console.log('Initialize error occured: ' + error);
  });
}

GSW.Tests.scanPressed = function() {
  console.log("scanPressed");
              navigator.gswhoneywellscanner.enableTrigger(function(result) {
        navigator.gswhoneywellscanner.softwareTriggerStart(function(result) {
          document.getElementById('userid').value = result.data;
          document.getElementById('character_set').value = result.character_set;
          document.getElementById('code_id').value = result.code_id;
          document.getElementById('aim_id').value = result.aim_id;
          document.getElementById('timestamp').value = result.timestamp;
          console.log('Software scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
        }, function(error) {
          console.log('Error occured: ' + error);
        });
              }, function(error) {
    console.log('Unable to enable trigger: ' + error);
  })
}

GSW.Tests.scanReleased = function() {
  console.log("scanReleased");
    navigator.gswhoneywellscanner.disableTrigger(function(result) {
      navigator.gswhoneywellscanner.softwareTriggerStop();
    }, function(error) {
      console.log('Unable to disable trigger: ' + error);
    })
}

  GSW.Tests.disable = function() {
    navigator.gswhoneywellscanner.disableTrigger(function(result) {
      console.log('Trigger disabled');
    }, function(error) {
      console.log('Unable to disable trigger: ' + error);
    })
  }
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);
            

Honeywell Scanner Listen

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
  // Cordova is now initialized. Have fun!
  console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
  navigator.gswhoneywellscanner.initialize(function(data) {
    console.log('initialize OK');
    navigator.gswhoneywellscanner.listen(function(result) {
      document.getElementById('data').value = result.data;
      document.getElementById('character_set').value = result.character_set;
      document.getElementById('code_id').value = result.code_id;
      document.getElementById('aim_id').value = result.aim_id;
      document.getElementById('timestamp').value = result.timestamp;
      console.log('Scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
    }, function(error) {
      console.log('Unable to listen: ' + error);
    });
    var enabled = true;
    document.getElementById("enable_trigger").disabled = true;
    document.getElementById("disable_trigger").disabled = false;
    document.getElementById('enable_trigger').addEventListener("click", function() {
      navigator.gswhoneywellscanner.enableTrigger(function(result) {
        enabled = true;
        document.getElementById("enable_trigger").disabled = true;
        document.getElementById("disable_trigger").disabled = false;
        console.log('Trigger enabled');
      }, function(error) {
        console.log('Unable to enable trigger: ' + error);
      })
    });
    document.getElementById('disable_trigger').addEventListener("click", function() {
      navigator.gswhoneywellscanner.disableTrigger(function(result) {
        enabled = false
        document.getElementById("enable_trigger").disabled = false;
        document.getElementById("disable_trigger").disabled = true;
        console.log('Trigger disabled');
      }, function(error) {
        console.log('Unable to disable trigger: ' + error);
      })
    });
  }, function(error) {
    console.log('Initialize error occured: ' + error);
    document.getElementById("enable_trigger").disabled = true;
    document.getElementById("disable_trigger").disabled = true;
    if(error == "Honeywell scanner decode service is unavailable on this device") {
      let notice = document.getElementById("noticeContainer");
      notice.style.display = "block";
      document.getElementById("error").innerHTML = "This device was not manufactured by Honeywell and is not compatible with this demo."
    }
  });
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);
            

Honeywell Scanner Field

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
  // Cordova is now initialized. Have fun!
  console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
  navigator.gswhoneywellscanner.initialize(function(data) {
    console.log('initialize OK');
    document.getElementById('userid').addEventListener("focus", GSW.Tests.enable);
    document.getElementById('userid').addEventListener("blur", GSW.Tests.disable);
    GSW.Tests.disable();
  }, function(error) {
    if(error == "Honeywell scanner decode service is unavailable on this device") {
      let notice = document.getElementById("noticeContainer");
      notice.style.display = "block";
      document.getElementById("error").innerHTML = "This device was not manufactured by Honeywell and is not compatible with this demo."
    } else console.log('Initialize error occured: ' + error);
  });
}

GSW.Tests.enable = function(event) {
  console.log('enable');
  navigator.gswhoneywellscanner.enableTrigger(function(result) {
    navigator.gswhoneywellscanner.listen(function(result) {
      document.getElementById('userid').value = result.data;
      document.getElementById('character_set').value = result.character_set;
      document.getElementById('code_id').value = result.code_id;
      document.getElementById('aim_id').value = result.aim_id;
      document.getElementById('timestamp').value = result.timestamp;
      console.log('Scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
    }, function(error) {
      console.log('Error occured: ' + error);
    });
  },function(error) {
    console.log('Unable to enable trigger: ' + error);
  })
}

  GSW.Tests.disable = function() {
    navigator.gswhoneywellscanner.disableTrigger(function(result) {
      console.log('Trigger disabled');
    }, function(error) {
      console.log('Unable to disable trigger: ' + error);
    })
  }

document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);
            

Zebra Scanner

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
  // Cordova is now initialized. Have fun!
  console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
  navigator.gswzebrascanner.initialize(function(data) {
    console.log('initialize OK');
    document.getElementById('scan_now').addEventListener("touchstart", GSW.Tests.scanPressed);
    document.getElementById('scan_now').addEventListener("touchend", GSW.Tests.scanReleased);
    document.getElementById('scan_now').addEventListener("touchmove", GSW.Tests.scanReleased);
    document.getElementById('scan_now').addEventListener("touchcancel", GSW.Tests.scanReleased);
    
    /* 
     * Disable trigger so user is not confused when trigger button is pressed. All scanning in this example 
     * is done from the software trigger.
     */
      GSW.Tests.disable();
  }, function(error) {
    if(error == "Zebra scanner decode service is unavailable on this device") {
      let notice = document.getElementById("noticeContainer");
      notice.style.display = "block";
      document.getElementById("error").innerHTML = "This device was not manufactured by Zebra and is not compatible with this demo."
    } else console.log('Initialize error occured: ' + error);
  });
}

GSW.Tests.scanPressed = function() {
  console.log("scanPressed");
              navigator.gswzebrascanner.enableTrigger(function(result) {
        navigator.gswzebrascanner.softwareTriggerStart(function(result) {
          document.getElementById('userid').value = result.data;
          document.getElementById('character_set').value = result.character_set;
          document.getElementById('code_id').value = result.code_id;
          document.getElementById('aim_id').value = result.aim_id;
          document.getElementById('timestamp').value = result.timestamp;
          console.log('Software scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
        }, function(error) {
          console.log('Error occured: ' + error);
        });
              }, function(error) {
    console.log('Unable to enable trigger: ' + error);
  });
}

GSW.Tests.scanReleased = function() {
  console.log("scanReleased");
    navigator.gswzebrascanner.disableTrigger(function(result) {
      navigator.gswzebrascanner.softwareTriggerStop();
    }, function(error) {
      console.log('Unable to disable trigger: ' + error);
    });
}

  GSW.Tests.disable = function() {
    navigator.gswzebrascanner.disableTrigger(function(result) {
      console.log('Trigger disabled');
    }, function(error) {
      console.log('Unable to disable trigger: ' + error);
    });
  }
  
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);
            

Zebra Scanner Listen

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
  // Cordova is now initialized. Have fun!
  console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
  navigator.gswzebrascanner.initialize(function(data) {
    console.log('initialize OK');
    navigator.gswzebrascanner.listen(function(result) {
      document.getElementById('data').value = result.data;
      document.getElementById('character_set').value = result.character_set;
      document.getElementById('code_id').value = result.code_id;
      document.getElementById('aim_id').value = result.aim_id;
      document.getElementById('timestamp').value = result.timestamp;
      console.log('Scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
    }, function(error) {
      console.log('Unable to listen: ' + error);
    });
    var enabled = true;
    document.getElementById("enable_trigger").disabled = true;
    document.getElementById("disable_trigger").disabled = false;
    document.getElementById('enable_trigger').addEventListener("click", function() {
      navigator.gswzebrascanner.enableTrigger(function(result) {
        enabled = true;
        document.getElementById("enable_trigger").disabled = true;
        document.getElementById("disable_trigger").disabled = false;
        console.log('Trigger enabled');
      }, function(error) {
        console.log('Unable to enable trigger: ' + error);
      })
    });
    document.getElementById('disable_trigger').addEventListener("click", function() {
      navigator.gswzebrascanner.disableTrigger(function(result) {
        enabled = false
        document.getElementById("enable_trigger").disabled = false;
        document.getElementById("disable_trigger").disabled = true;
        console.log('Trigger disabled');
      }, function(error) {
        console.log('Unable to disable trigger: ' + error);
      })
    });
  }, function(error) {
    console.log('Initialize error occured: ' + error);
    document.getElementById("enable_trigger").disabled = true;
    document.getElementById("disable_trigger").disabled = true;
    if(error == "Zebra scanner decode service is unavailable on this device") {
      let notice = document.getElementById("noticeContainer");
      notice.style.display = "block";
      document.getElementById("error").innerHTML = "This device was not manufactured by Zebra and is not compatible with this demo."
    }
  });
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);
            

Zebra Scanner Field

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};
GSW.Tests.onDeviceReady = function() {
  // Cordova is now initialized. Have fun!
  console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
  navigator.gswzebrascanner.initialize(function(data) {
    console.log('initialize OK');
    document.getElementById('userid').addEventListener("focus", GSW.Tests.enable);
    document.getElementById('userid').addEventListener("blur", GSW.Tests.disable);
    GSW.Tests.disable();
  }, function(error) {
    if(error == "Zebra scanner decode service is unavailable on this device") {
      let notice = document.getElementById("noticeContainer");
      notice.style.display = "block";
      document.getElementById("error").innerHTML = "This device was not manufactured by Zebra and is not compatible with this demo."
    } else console.log('Initialize error occured: ' + error);
  });
}

GSW.Tests.enable = function(event) {
  console.log('enable');
  navigator.gswzebrascanner.enableTrigger(function(result) {
    navigator.gswzebrascanner.listen(function(result) {
      document.getElementById('userid').value = result.data;
      document.getElementById('character_set').value = result.character_set;
      document.getElementById('code_id').value = result.code_id;
      document.getElementById('aim_id').value = result.aim_id;
      document.getElementById('timestamp').value = result.timestamp;
      console.log('Scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
    }, function(error) {
      console.log('Error occured: ' + error);
    });
  },function(error) {
    console.log('Unable to enable trigger: ' + error);
  })
}

  GSW.Tests.disable = function() {
    navigator.gswzebrascanner.disableTrigger(function(result) {
      console.log('Trigger disabled');
    }, function(error) {
      console.log('Unable to disable trigger: ' + error);
    })
  }

document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);
            

Keyence Scanner

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
  // Cordova is now initialized. Have fun!
  console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
  navigator.gswkeyencescanner.initialize(function(data) {
    console.log('initialize OK');
    document.getElementById('scan_now').addEventListener("touchstart", GSW.Tests.scanPressed);
    document.getElementById('scan_now').addEventListener("touchend", GSW.Tests.scanReleased);
    document.getElementById('scan_now').addEventListener("touchmove", GSW.Tests.scanReleased);
    document.getElementById('scan_now').addEventListener("touchcancel", GSW.Tests.scanReleased);
    
    /* 
     * Disable trigger so user is not confused when trigger button is pressed. All scanning in this example 
     * is done from the software trigger.
     */
      GSW.Tests.disable();
  }, function(error) {
    if(error == "Keyence scanner decode service is unavailable on this device") {
      let notice = document.getElementById("noticeContainer");
      notice.style.display = "block";
      document.getElementById("error").innerHTML = "This device was not manufactured by Keyence and is not compatible with this demo."
    } else console.log('Initialize error occured: ' + error);
  });
}

GSW.Tests.scanPressed = function() {
  console.log("scanPressed");
              navigator.gswkeyencescanner.enableTrigger(function(result) {
        navigator.gswkeyencescanner.softwareTriggerStart(function(result) {
          document.getElementById('userid').value = result.data;
          document.getElementById('character_set').value = result.character_set;
          document.getElementById('code_id').value = result.code_id;
          document.getElementById('aim_id').value = result.aim_id;
          document.getElementById('timestamp').value = result.timestamp;
          console.log('Software scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
        }, function(error) {
          console.log('Error occured: ' + error);
        });
              }, function(error) {
    console.log('Unable to enable trigger: ' + error);
  });
}

GSW.Tests.scanReleased = function() {
  console.log("scanReleased");
    navigator.gswkeyencescanner.disableTrigger(function(result) {
      navigator.gswkeyencescanner.softwareTriggerStop();
    }, function(error) {
      console.log('Unable to disable trigger: ' + error);
    });
}

  GSW.Tests.disable = function() {
    navigator.gswkeyencescanner.disableTrigger(function(result) {
      console.log('Trigger disabled');
    }, function(error) {
      console.log('Unable to disable trigger: ' + error);
    });
  }
  
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);
            

Keyence Scanner Listen

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
  // Cordova is now initialized. Have fun!
  console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
  navigator.gswkeyencescanner.initialize(function(data) {
    console.log('initialize OK');
    navigator.gswkeyencescanner.listen(function(result) {
      document.getElementById('data').value = result.data;
      document.getElementById('character_set').value = result.character_set;
      document.getElementById('code_id').value = result.code_id;
      document.getElementById('aim_id').value = result.aim_id;
      document.getElementById('timestamp').value = result.timestamp;
      console.log('Scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
    }, function(error) {
      console.log('Unable to listen: ' + error);
    });
    var enabled = true;
    document.getElementById("enable_trigger").disabled = true;
    document.getElementById("disable_trigger").disabled = false;
    document.getElementById('enable_trigger').addEventListener("click", function() {
      navigator.gswkeyencescanner.enableTrigger(function(result) {
        enabled = true;
        document.getElementById("enable_trigger").disabled = true;
        document.getElementById("disable_trigger").disabled = false;
        console.log('Trigger enabled');
      }, function(error) {
        console.log('Unable to enable trigger: ' + error);
      })
    });
    document.getElementById('disable_trigger').addEventListener("click", function() {
      navigator.gswkeyencescanner.disableTrigger(function(result) {
        enabled = false
        document.getElementById("enable_trigger").disabled = false;
        document.getElementById("disable_trigger").disabled = true;
        console.log('Trigger disabled');
      }, function(error) {
        console.log('Unable to disable trigger: ' + error);
      })
    });
  }, function(error) {
    console.log('Initialize error occured: ' + error);
    document.getElementById("enable_trigger").disabled = true;
    document.getElementById("disable_trigger").disabled = true;
    if(error == "Keyence scanner decode service is unavailable on this device") {
      let notice = document.getElementById("noticeContainer");
      notice.style.display = "block";
      document.getElementById("error").innerHTML = "This device was not manufactured by Keyence and is not compatible with this demo."
    }
  });
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);
            

Keyence Scanner Field

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
  // Cordova is now initialized. Have fun!
  console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
  navigator.gswkeyencescanner.initialize(function(data) {
    console.log('initialize OK');
    document.getElementById('userid').addEventListener("focus", GSW.Tests.enable);
    document.getElementById('userid').addEventListener("blur", GSW.Tests.disable);
    GSW.Tests.disable();
  }, function(error) {
    if(error == "Keyence scanner decode service is unavailable on this device") {
      let notice = document.getElementById("noticeContainer");
      notice.style.display = "block";
      document.getElementById("error").innerHTML = "This device was not manufactured by Keyence and is not compatible with this demo."
    } else console.log('Initialize error occured: ' + error);
  });
}

GSW.Tests.enable = function(event) {
  console.log('enable');
  navigator.gswkeyencescanner.enableTrigger(function(result) {
    navigator.gswkeyencescanner.listen(function(result) {
      document.getElementById('userid').value = result.data;
      document.getElementById('character_set').value = result.character_set;
      document.getElementById('code_id').value = result.code_id;
      document.getElementById('aim_id').value = result.aim_id;
      document.getElementById('timestamp').value = result.timestamp;
      console.log('Scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
    }, function(error) {
      console.log('Error occured: ' + error);
    });
  },function(error) {
    console.log('Unable to enable trigger: ' + error);
  })
}

  GSW.Tests.disable = function() {
    navigator.gswkeyencescanner.disableTrigger(function(result) {
      console.log('Trigger disabled');
    }, function(error) {
      console.log('Unable to disable trigger: ' + error);
    })
  }

document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);
            

CipherLab Scanner Field

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onGswScannerReady = function() {
    // Cordova is now initialized. Have fun!
    console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
    navigator.gswcipherlabscanner.initialize(function(data) {
        console.log('initialize OK');
        document.getElementById('scan_now').addEventListener("touchstart", GSW.Tests.scanPressed);
        document.getElementById('scan_now').addEventListener("touchend", GSW.Tests.scanReleased);
        document.getElementById('scan_now').addEventListener("touchmove", GSW.Tests.scanReleased);
        document.getElementById('scan_now').addEventListener("touchcancel", GSW.Tests.scanReleased);
        GSW.Tests.disable();
    }, function(error) {
        if (error == "CipherLab scanner decode service is unavailable on this device") {
            let notice = document.getElementById("noticeContainer");
            notice.style.display = "block";
            document.getElementById("error").innerHTML = "This device was not manufactured by CipherLab and is not compatible with this demo."
        } else console.log('Initialize error occured: ' + error);
    });
}

GSW.Tests.scanPressed = function() {
    console.log("scanPressed");
    navigator.gswcipherlabscanner.enableTrigger(function(result) {
        navigator.gswcipherlabscanner.softwareTriggerStart(function(result) {
            document.getElementById('userid').value = result.data;
            document.getElementById('character_set').value = result.character_set;
            document.getElementById('code_id').value = result.code_id;
            document.getElementById('aim_id').value = result.aim_id;
            document.getElementById('timestamp').value = result.timestamp;
            console.log('Software scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
        }, function(error) {
            console.log('Error occured: ' + error);
        });
    }, function(error) {
        console.log('Unable to enable trigger: ' + error);
    })
}

GSW.Tests.scanReleased = function() {
    console.log("scanReleased");
    navigator.gswcipherlabscanner.disableTrigger(function(result) {
        navigator.gswcipherlabscanner.softwareTriggerStop();
    }, function(error) {
        console.log('Unable to disable trigger: ' + error);
    })
}

GSW.Tests.disable = function() {
    navigator.gswcipherlabscanner.disableTrigger(function(result) {
        console.log('Trigger disabled');
    }, function(error) {
        console.log('Unable to disable trigger: ' + error);
    })
}
document.addEventListener('gswscannerready', GSW.Tests.onGswScannerReady, false);            

CipherLab Scanner Listen

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onGswScannerReady = function() {
    // Cordova is now initialized. Have fun!
    console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
    navigator.gswcipherlabscanner.initialize(function(data) {
        console.log('initialize OK');
        navigator.gswcipherlabscanner.listen(function(result) {
            document.getElementById('userid').value = result.data;
            document.getElementById('character_set').value = result.character_set;
            document.getElementById('code_id').value = result.code_id;
            document.getElementById('aim_id').value = result.aim_id;
            document.getElementById('timestamp').value = result.timestamp;
            console.log('Scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
        }, function(error) {
            console.log('Unable to listen: ' + error);
        });
        var enabled = true;
        document.getElementById("enable_trigger").disabled = true;
        document.getElementById("disable_trigger").disabled = false;
        document.getElementById('enable_trigger').addEventListener("click", function() {
            navigator.gswcipherlabscanner.enableTrigger(function(result) {
                enabled = true;
                document.getElementById("enable_trigger").disabled = true;
                document.getElementById("disable_trigger").disabled = false;
                console.log('Trigger enabled');
            }, function(error) {
                console.log('Unable to enable trigger: ' + error);
            })
        });
        document.getElementById('disable_trigger').addEventListener("click", function() {
            navigator.gswcipherlabscanner.disableTrigger(function(result) {
                enabled = false
                document.getElementById("enable_trigger").disabled = false;
                document.getElementById("disable_trigger").disabled = true;
                console.log('Trigger disabled');
            }, function(error) {
                console.log('Unable to disable trigger: ' + error);
            })
        });
    }, function(error) {
        console.log('Initialize error occured: ' + error);
        document.getElementById("enable_trigger").disabled = true;
        document.getElementById("disable_trigger").disabled = true;
        if (error == "CipherLab scanner decode service is unavailable on this device") {
            let notice = document.getElementById("noticeContainer");
            notice.style.display = "block";
            document.getElementById("error").innerHTML = "This device was not manufactured by CipherLab and is not compatible with this demo."
        } else console.log('Initialize error occured: ' + error);
    });
}
document.addEventListener('gswscannerready', GSW.Tests.onGswScannerReady, false);            

CipherLab Scanner Field

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onGswScannerReady = function() {
    // Cordova is now initialized. Have fun!
    console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
    navigator.gswcipherlabscanner.initialize(function(data) {
        console.log('initialize OK');
        document.getElementById('userid').addEventListener("focus", GSW.Tests.enable);
        document.getElementById('userid').addEventListener("blur", GSW.Tests.disable);
        GSW.Tests.disable();
    }, function(error) {
        if (error == "CipherLab scanner decode service is unavailable on this device") {
            let notice = document.getElementById("noticeContainer");
            notice.style.display = "block";
            document.getElementById("error").innerHTML = "This device was not manufactured by CipherLab and is not compatible with this demo."
        } else console.log('Initialize error occured: ' + error);
    });
}

GSW.Tests.enable = function(event) {
    console.log('enable');
    navigator.gswcipherlabscanner.enableTrigger(function(result) {
        navigator.gswcipherlabscanner.listen(function(result) {
            document.getElementById('userid').value = result.data;
            document.getElementById('character_set').value = result.character_set;
            document.getElementById('code_id').value = result.code_id;
            document.getElementById('aim_id').value = result.aim_id;
            document.getElementById('timestamp').value = result.timestamp;
            console.log('Scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
        }, function(error) {
            console.log('Error occured: ' + error);
        });
    }, function(error) {
        console.log('Unable to enable trigger: ' + error);
    })
}

GSW.Tests.disable = function() {
    navigator.gswcipherlabscanner.disableTrigger(function(result) {
        console.log('Trigger disabled');
    }, function(error) {
        console.log('Unable to disable trigger: ' + error);
    })
}

document.addEventListener('gswscannerready', GSW.Tests.onGswScannerReady, false);            

Telemetry & Device Information



Battery Status

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized. Have fun!
	console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);

	GSW.Tests.onBatteryStatus = function(status) {

		let percentage = document.querySelector('.percentage');
		let percent = document.querySelector('.percent');
		let charging = document.querySelector('.charging');
		let batteryShape = document.querySelector('.batteryShape');

		percentage.style.width = status.level + '%';
		percent.innerHTML = status.level + '%';

		if (status.isPlugged == true) {
			charging.style.color = "green";
			batteryShape.style.borderColor = "green";
			charging.innerHTML = "Status: Charging";
		} else {
			charging.style.color = "black";
			batteryShape.style.borderColor = "black";
			charging.innerHTML = "Status: Not Charging";
		}

	}


	GSW.Tests.onBatteryLow = function(status) {
		// Handle the battery low event
		alert("Battery Level Low :" + status.level + "%");
	}


	GSW.Tests.onBatteryCritical = function(status) {
		let batteryShape = document.querySelector('.batteryShape');
		batteryShape.style.borderColor = "red";
		alert("Battery Level Critical " + status.level + "%\nRecharge Soon!");
	}

	//for cordova-plugin-battery-status
	window.addEventListener("batterystatus", GSW.Tests.onBatteryStatus, false);
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);
  
            

Cordova Device Plugin

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized. Have fun!
	console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);
	GSW.Tests.displayVariables = function() {
        document.getElementById("cordova").innerHTML = device.cordova;
        document.getElementById("model").innerHTML = device.model;
        document.getElementById("platform").innerHTML = device.platform;
        document.getElementById("uuid").innerHTML = device.uuid;
        document.getElementById("version").innerHTML = device.version;
        document.getElementById("manufacturer").innerHTML = device.manufacturer;
        document.getElementById("isVirtual").innerHTML = device.isVirtual;
        document.getElementById("serial").innerHTML = device.serial;
	}
	document.getElementById("display").addEventListener("click", GSW.Tests.displayVariables);
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);  
            

Geolocation

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized. Have fun!
	console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);
	
	// onError Callback receives a PositionError object
	GSW.Tests.onError = function(error) {
	    if(error.code == 1){
	        alert('This error could be one of two options \n 1. Geolocation permissions are not enabled. \n 2. You have accessed this site via HTTP, please use HTTPS.')
	    }else{
		alert('Geolocation:' + '\n' +
			  'code: '    + error.code    + '\n' +
			  'message: ' + error.message + '\n');    			        
	    }

	}

	GSW.Tests.onSuccess = function(position) {
		console.log('Geolocation:' +
					'Latitude: '          + position.coords.latitude          + ' ' +
					'Longitude: '         + position.coords.longitude         + ' ' +
					'Altitude: '          + position.coords.altitude          + ' ' +
					'Accuracy: '          + position.coords.accuracy          + ' ' +
					'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + ' ' +
					'Heading: '           + position.coords.heading           + ' ' +
					'Speed: '             + position.coords.speed             + ' ' +
					'Timestamp: '         + position.timestamp);
		document.getElementById("geo_latitude").innerHTML = position.coords.latitude;
		document.getElementById("geo_longtitude").innerHTML = position.coords.longitude;
		document.getElementById("geo_altitude").innerHTML = position.coords.altitude;
		document.getElementById("geo_accuracy").innerHTML = position.coords.accuracy;
		//document.getElementById("geo_altitude_accuracy").innerHTML = position.coords.altitudeAccuracy;
		document.getElementById("geo_heading").innerHTML = position.coords.heading;
		document.getElementById("geo_speed").innerHTML = position.coords.speed;
	}
	GSW.Tests.watchPosition = function() {
        navigator.geolocation.watchPosition(GSW.Tests.onSuccess, GSW.Tests.onError, { timeout: 30000, enableHighAccuracy: true });
	}
document.getElementById("start").addEventListener("click", GSW.Tests.watchPosition);
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);   
            

GSW Variables

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized. Have fun!
	console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);
	GSW.Tests.getVariables = function() {
		var cont = document.getElementById('variables');
		var ul = document.createElement('ul');
		ul.setAttribute('style', 'padding: 0; margin: 0;');
		ul.setAttribute('id', 'theList');

		for (var prop in navigator.gswconnectbot.clientStrings) {
			if (navigator.gswconnectbot.clientStrings.hasOwnProperty(prop)) {
				var li = document.createElement('li');
				li.innerHTML = (prop + ' = ' + navigator.gswconnectbot.clientStrings[prop]);
				li.setAttribute('style', 'display: block;');
				ul.appendChild(li);
			}
		}
		cont.appendChild(ul);
	}
	document.getElementById("display").addEventListener("click", GSW.Tests.getVariables);
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);  
            

Network Information

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized. Have fun!
	console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);
	GSW.Tests.displayNetwork = function() {
		var cont = document.getElementById('network');
		let status = navigator.connection.type;
		cont.innerHTML = "Current Network Type: "+ navigator.connection.type.toUpperCase();
	}
	document.getElementById("display").addEventListener("click", GSW.Tests.displayNetwork);
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);   
            

Device Control



Barcode Scanner (Camera)

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized. Have fun!
	console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);

	GSW.Tests.scan = function(el) {
		var params = {
			'prompt_message': 'Scan a barcode', // Change the info message. A blank message ('') will show a default message
			'orientation_locked': false, // Lock the orientation screen
			'camera_id': 0, // Choose the camera source
			'beep_enabled': true, // Enables a beep after the scan
			'scan_type': 'normal', // Types of scan mode: normal = default black with white background / inverted = white bars on dark background / mixed = normal and inverted modes
			'barcode_formats': [
				'QR_CODE',
				'CODE_39',
				'CODE_128',
				'UPC_A'
			], // Put a list of formats that the scanner will find. A blank list ([]) will enable scan of all barcode types
			'extras': {} // Additional extra parameters. See [ZXing Journey Apps][1] IntentIntegrator and Intents for more details
		};

		function onSuccess(result) {
			console.log(result);
			el.value = result;
		}

		function onFailure(result) {
			console.log(result);
		}
		window.plugins.zxingPlugin.scan(params, onSuccess, onFailure);
	}
	document.getElementById('userid').addEventListener("click", function() {
		document.getElementById('userid').addEventListener("focus", GSW.Tests.scan(document.getElementById('userid')), false);
	});
}

document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);  
            

Camera

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};


GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized.

	console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);

	GSW.Tests.cameraTakePicture = function() {
		navigator.camera.getPicture(GSW.Tests.onSuccess, GSW.Tests.onFail, {
			quality: 50,
			correctOrientation: true,
			destinationType: Camera.DestinationType.DATA_URL
		});
	}

	GSW.Tests.onSuccess = function(imageData) {
		console.log('onSuccess' + imageData);
		var image = document.getElementById('myImage');
		image.src = "data:image/jpeg;base64," + imageData;
	}

	GSW.Tests.onFail = function(message) {
		var para = document.getElementById('alert');
		let code = message;
		if(code === 20){
		    para.innerHTML = "Camera permissions are not enabled. Please enable camera permissions for GSW ConnectBot";
		}else{
			para.innerHTML = "Operation was not completed due to: " + message;				    
		}
	}
	document.getElementById("cameraTakePicture").addEventListener("click", GSW.Tests.cameraTakePicture);
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);  
            

Dialogs

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};


GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized.

	console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);

	GSW.Tests.dialogAlert = function() {
		var message = "The best Android (Telnet, SSH, and Web) client!";
		var title = "ALERT: GSW ConnectBot";
		var buttonName = "Close Alert";
		navigator.notification.alert(message, alertCallback, title, buttonName);

		function alertCallback() {
			console.log("Alert is Dismissed!");
		}
	}
	GSW.Tests.dialogConfirm = function() {
		var message = "Is GSW ConnectBot the solution for you?";
		var title = "CONFIRM";
		var buttonLabels = "YES,YES";
		navigator.notification.confirm(message, confirmCallback, title, buttonLabels);

		function confirmCallback(buttonIndex) {
			console.log("You clicked " + buttonIndex + " button!");
		}
	}
	GSW.Tests.dialogPrompt = function() {
		var message = "Am I Prompt Dialog?";
		var title = "PROMPT";
		var buttonLabels = ["YES", "NO"];
		var defaultText = "Default"
		navigator.notification.prompt(message, promptCallback,
			title, buttonLabels, defaultText);

		function promptCallback(result) {
			console.log("You clicked " + result.buttonIndex + " button! \n" +
				"You entered " + result.input1);
		}
	}
	GSW.Tests.dialogBeep = function() {
		var times = 2;
		navigator.notification.beep(times);
	}
	document.getElementById("dialogAlert").addEventListener("click", GSW.Tests.dialogAlert);
	document.getElementById("dialogConfirm").addEventListener("click", GSW.Tests.dialogConfirm);
	document.getElementById("dialogPrompt").addEventListener("click", GSW.Tests.dialogPrompt);
	document.getElementById("dialogBeep").addEventListener("click", GSW.Tests.dialogBeep);
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);  
            

File Storage

/*
 *	cordova.file.dataDirectory							/data/data/com.gsw.connectbot
 *	cordova.file.applicationStorageDirectory			/data/data/com.gsw.connectbot/files
 *	cordova.file.cacheDirectory							/data/data/com.gsw.connectbot/cache
 *	cordova.file.externalApplicationStorageDirectory 	/sdcard/Android/data/com.gsw.connectbot
 *	cordova.file.externalDataDirectory					/sdcard/Android/data/com.gsw.connectbot/files
 *	cordova.file.externalCacheDirectory					/sdcard/Android/data/com.gsw.connectbot/cache
 */
var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};


GSW.Tests.onDeviceReady = function() {
    console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);
    GSW.Tests.fsPath = cordova.file.externalDataDirectory;
    console.log("fspath set to " + GSW.Tests.fsPath);

    GSW.Tests.errorHandler = function(target, fileName, operation, e) {
        var msg = ''

        switch (e.code) {
            case FileError.QUOTA_EXCEEDED_ERR:
                msg = 'Storage quota exceeded'
                break
            case FileError.NOT_FOUND_ERR:
                msg = 'File not found'
                break
            case FileError.SECURITY_ERR:
                msg = 'Security error'
                break
            case FileError.INVALID_MODIFICATION_ERR:
                msg = 'Invalid modification'
                break
            case FileError.INVALID_STATE_ERR:
                msg = 'Invalid state'
                break
            default:
                msg = 'Unknown error ' + e.code
                break
        }

        var error_message = 'Error in ' + operation + ' (' + fileName + '): ' + msg;
        console.log(error_message)
        document.getElementById(target).innerHTML = error_message;
        if (target == "read_error")
            document.getElementById("data_from_file").innerHTML = "";
        if (target == "write_error")
            document.getElementById("success").innerHTML = "";
    }

    GSW.Tests.initFileRead = function() {
        var readFileName = document.getElementById('fileNameRead').value;
        let rFN = readFileName.concat(".json");
        GSW.Tests.readFromFile(rFN, function(data) {
            document.getElementById("data_from_file").innerHTML = data;
            document.getElementById("read_error").innerHTML = "";
        });

    }

    GSW.Tests.readFromFile = function(fileName, cb) {
        var pathToFile = GSW.Tests.fsPath + fileName
        window.resolveLocalFileSystemURL(
            //path
            pathToFile,
            //success handler
            function(fileEntry) {
                if (!fileEntry.isFile) {
                    GSW.Tests.errorHandler("read_error", fileName, "file check", new FileError(FileError.NOT_FOUND_ERR));
                    return;
                }
                fileEntry.file(function(file) {
                        var reader = new FileReader()
                        reader.onloadend = function(e) {
                            cb(JSON.parse(this.result))
                        }

                        reader.readAsText(file)
                    },

                    //error handler
                    GSW.Tests.errorHandler.bind(null, "read_error", fileName, "fileEntry.file"))
            },

            //error handler
            GSW.Tests.errorHandler.bind(null, "read_error", fileName, "resolveLocalFileSystemURL")
        )
    }


    GSW.Tests.writeToFile = function(fileName, data) {
        console.log("path in write: " + GSW.Tests.fsPath);
        data = JSON.stringify(data, null, '\t')
        window.resolveLocalFileSystemURL(
            GSW.Tests.fsPath,
            function(directoryEntry) {
                directoryEntry.getFile(
                    fileName, {
                        create: true
                    },

                    //success handler
                    function(fileEntry) {
                        fileEntry.createWriter(function(fileWriter) {
                                fileWriter.onwriteend = function(e) {
                                    // for real-world usage, you might consider passing a success callback
                                    console.log('Write of file "' + fileName + '"" completed.')
                                    document.getElementById("write_error").innerHTML = "";
                                    document.getElementById("success").innerHTML = "Write operation successful";
                                }

                                fileWriter.onerror = function(e) {
                                    // you could hook this up with our global error handler, or pass in an error callback
                                    console.log('Write failed: ' + e.toString())
                                    //GSW.Tests.errorHandler("write_error", fileName, "fileWriter", e);
                                }

                                var blob = new Blob([data], {
                                    type: 'text/plain'
                                })
                                fileWriter.write(blob)
                            },

                            //error handler
                            GSW.Tests.errorHandler.bind(null, "write_error", fileName, "createWriter"))
                    },

                    //error handler
                    GSW.Tests.errorHandler.bind(null, "write_error", fileName, "getFile")
                )
            },
            GSW.Tests.errorHandler.bind(null, "write_error", fileName, "resolveLocalFileSystemURL")
        )

    }


    GSW.Tests.startProcess = function() {
        // Cordova is now initialized Have fun!
        var text = document.getElementById('inputText').value;
        var file = document.getElementById('fileName').value;
        let finalFileName = file.concat(".json");
        //			var path = document.getElementById("location").value;
        //			console.log(path);
        //		GSW.Tests.fsPath = path;
        GSW.Tests.writeToFile(finalFileName, text);;
        console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);
    }
    document.getElementById("start").addEventListener("click", GSW.Tests.startProcess);
    document.getElementById("read").addEventListener("click", GSW.Tests.initFileRead);
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);  
            

File Transfer

// Example Code Coming Soon
            

Media Player

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized. Have fun!
	console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);

	var myMedia = null;
	GSW.Tests.playAudio = function() {
		console.log("check 1");
		var src = "https://sshserver.com/android/piano.mp3";
		if (myMedia === null) {
			myMedia = new Media(src, GSW.Tests.onSuccess, GSW.Tests.onError);

			GSW.Tests.onSuccess = function() {
				console.log("playAudio Success");
			}

			GSW.Tests.onError = function(error) {
				console.log("playAudio Error: " + error.code);
			}
		}
		myMedia.play();
	}
	GSW.Tests.pauseAudio = function() {
		if (myMedia) {
			myMedia.pause();
		}
	}

	GSW.Tests.stopAudio = function() {
		if (myMedia) {
			myMedia.stop();
		}
		myMedia = null;
	}
	var volumeValue = 0.5;
	GSW.Tests.volumeUp = function() {
		if (myMedia && volumeValue < 1) {
			myMedia.setVolume(volumeValue += 0.1);
		}
	}

	GSW.Tests.volumeDown = function() {
		if (myMedia && volumeValue > 0) {
			myMedia.setVolume(volumeValue -= 0.1);
		}
	}
	document.getElementById("playAudio").addEventListener("click", GSW.Tests.playAudio);
	document.getElementById("pauseAudio").addEventListener("click", GSW.Tests.pauseAudio);
	document.getElementById("stopAudio").addEventListener("click", GSW.Tests.stopAudio);
	document.getElementById("volumeUp").addEventListener("click", GSW.Tests.volumeUp);
	document.getElementById("volumeDown").addEventListener("click", GSW.Tests.volumeDown);

}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);   
            

Media Capture

// Example Code Coming Soon
            

Screen Orientation

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
	window.addEventListener("orientationchange", function() {
		console.log(screen.orientation.type);
	});
	GSW.Tests.orientationChange = function(mode) {
	    let portrait = document.getElementById("portrait");
	    let revPortrait = document.getElementById("revPortrait");
	    let landscape = document.getElementById("landscape");
	    let revLandscape = document.getElementById("revLandscape");
		let status = document.getElementById("currOrientation");
		portrait.disabled = false;
	    revPortrait.disabled = false;
		landscape.disabled = false;
		revLandscape.disabled = false;
        if(mode == 0){
			portrait.disabled = true;
			screen.orientation.lock('portrait-primary');
			status.innerHTML = 'Current Orientation Is: portrait-primary ';
        }
        else if(mode == 1){
			revPortrait.disabled = true;
			screen.orientation.lock('portrait-secondary');
			status.innerHTML = 'Current Orientation Is: portrait-secondary';
        }
        else if(mode == 2){
			landscape.disabled = true;
		    screen.orientation.lock('landscape-primary');
		    status.innerHTML = 'Current Orientation Is: landscape-primary';
        }
        else if(mode == 3){
			revLandscape.disabled = true;
		    screen.orientation.lock('landscape-secondary');
		    status.innerHTML = 'Current Orientation Is: landscape-secondary';
        }
        else{
		    let status = document.getElementById("currOrientation");
		    status.innerHTML = "Current Orientation Is: Unlocked";
           screen.orientation.unlock();
        }
	}
	document.getElementById("portrait").addEventListener("click", function(){GSW.Tests.orientationChange(0)});
	document.getElementById("landscape").addEventListener("click", function(){GSW.Tests.orientationChange(2)});
	document.getElementById("revPortrait").addEventListener("click", function(){GSW.Tests.orientationChange(1)});
	document.getElementById("revLandscape").addEventListener("click", function(){GSW.Tests.orientationChange(3)});
	document.getElementById("unlock").addEventListener("click", function(){GSW.Tests.orientationChange(4)});
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);  
            

Status Bar

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized. Have fun!
	console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);
    StatusBar.overlaysWebView(true);
    
	document.getElementById("styleDefault").addEventListener("click",  function() {
        StatusBar.styleDefault();
        StatusBar.backgroundColorByName("white");
	});
	document.getElementById("styleLightContent").addEventListener("click",  function() {
        StatusBar.styleLightContent(); 
        StatusBar.backgroundColorByName("black"); 
	});
	document.getElementById("backgroundColorByName").addEventListener("click",  function() {
        StatusBar.backgroundColorByName("red");            
	});
	document.getElementById("backgroundColorByHexString").addEventListener("click",  function() {
        StatusBar.backgroundColorByHexString("#32DE84");            
	});
	document.getElementById("hide").addEventListener("click",  function() {
        StatusBar.hide();            
	});
	document.getElementById("show").addEventListener("click",  function() {
        StatusBar.show();
        StatusBar.backgroundColorByName("white"); 
        StatusBar.styleDefault();
	});
    
}

document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);  
            

Text To Speech

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized. Have fun!
	console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);
	GSW.Tests.tts = function() {
	    let text = document.getElementById("user-input").value;
          TTS
              .speak({
                text: text,
                identifier: '',  // location for specific voice, can be local or public
                rate: 1,
                pitch: 0.9,
                cancel: true
              }).then(function () {
             console.log('success');
          }, function (reason) {
            alert(reason);
          });
	}
	document.getElementById("tts").addEventListener("click", GSW.Tests.tts);
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);  
            

Vibration

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized. Have fun!
	console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);

	GSW.Tests.vibrateOne = function() {
	    let duration = 1000;
		navigator.vibrate(duration);
	};
	GSW.Tests.vibrateTwo = function() {
	    let duration = 2000;
		navigator.vibrate(duration);
	};
	GSW.Tests.vibrateThree = function() {
	    let duration = 1000;
		navigator.vibrate([duration, duration, duration]);
	};
	GSW.Tests.vibrateFour = function() {
	    let duration = 2000;
		navigator.vibrate([duration, duration, duration]);
	};
	document.getElementById("1000").addEventListener("click", GSW.Tests.vibrateOne);
	document.getElementById("2000").addEventListener("click", GSW.Tests.vibrateTwo);
	document.getElementById("3000").addEventListener("click", GSW.Tests.vibrateThree);
	document.getElementById("4000").addEventListener("click", GSW.Tests.vibrateFour);
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);  
            

Zebra Bluetooth Printing

var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized. Have fun!
	console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);

	GSW.Tests.print = function() {
		//Gathering User Input
		var headingInput = document.getElementById("heading").value;
		var text = document.getElementById("text").value;
		var heading = headingInput.toUpperCase();


		//Formatting for Printer
		var headingFormat = "! U1 JOURNAL\r\n" +
			"! U1 SETLP 4 0 47\r\n";
		var textFormat = "! U1 SETLP 7 0 24\r\n";
		var barcode = "! U1 CENTER\r\n" +
			"! U1 B 128 1 1 100 0 0 59285691 ST 187.10 T 2.60\r\n";


		// Inserting user input into correct format
		var finalHeading = headingFormat + heading + "\r\n";
		var finalText = textFormat + text + "\r\n";

		// Creating final label string to print
		var label = finalHeading + finalText + barcode;

		navigator.gswconnectbot.printString(function() {
				document.getElementById("printSuccess").innerHTML = "Print Success"
			},
			function(e) {
				document.getElementById("printSuccess") = "print error: " + e;
			}, label);
	}

	GSW.Tests.printDemo = function() {
		var label = "! U1 JOURNAL\r\n" +
			"! U1 SETLP 4 0 47\r\n" +
			" YOURCO RETAIL STORES\r\n" +
			"! U1 SETLP 7 0 24\r\n" +
			" 14:40 PM      Thursday, 06/04/20\r\n" +
			" Quantity  Item         Unit   Total\r\n" +
			" 1         Babelfish    $4.20  $4.20\r\n" +
			"           Tax:            5%  $0.21\r\n" +
			"! U1 SETSP 5\r\n" +
			"      Total:! U1 SETSP 0\r\n" +
			" $4.41\r\n" +
			"Thank you for shopping at YOURCO\r\n" +
			"! U1 CENTER\r\n" +
			"! U1 B 128 1 2 100 0 0 59285691 ST 187.10 T 2.60\r\n";
		navigator.gswconnectbot.printString(function() {
				document.getElementById("printSuccess").innerHTML = "Print Success"
			},
			function(e) {
				document.getElementById("printSuccess") = "print error: " + e;
			},
			label);

	}
	document.getElementById("userInput").addEventListener("click", GSW.Tests.print);			
	document.getElementById("demoPrint").addEventListener("click", GSW.Tests.printDemo);			
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);