LaunchMyApp.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. (function () {
  2. "use strict";
  3. var remainingAttempts = 10;
  4. function waitForAndCallHandlerFunction(url) {
  5. if (typeof window.handleOpenURL === "function") {
  6. // Clear the intent when we have a handler (note that this is only done when the preference 'CustomURLSchemePluginClearsAndroidIntent' is 'true' in config.xml
  7. cordova.exec(
  8. null,
  9. null,
  10. "LaunchMyApp",
  11. "clearIntent",
  12. []);
  13. window.handleOpenURL(url);
  14. } else if (remainingAttempts-- > 0) {
  15. setTimeout(function(){waitForAndCallHandlerFunction(url);}, 500);
  16. }
  17. }
  18. function triggerOpenURL() {
  19. cordova.exec(
  20. waitForAndCallHandlerFunction,
  21. null,
  22. "LaunchMyApp",
  23. "checkIntent",
  24. []);
  25. }
  26. document.addEventListener("deviceready", triggerOpenURL, false);
  27. var launchmyapp = {
  28. getLastIntent: function(success, failure) {
  29. cordova.exec(
  30. success,
  31. failure,
  32. "LaunchMyApp",
  33. "getLastIntent",
  34. []);
  35. }
  36. }
  37. module.exports = launchmyapp;
  38. }());