0

I have a phonegap project built for android and uses cordova. I planted a web-based app in this phonegap project. This app has one html page, index.html. In this index file, onDeviceReady() function is not called. However, this page is working perfect, only that it is called from mainactivity and for some reason it does not step into this function. It's probably overriden by a cordova function. Question: How do I make this function work in index.html file? Which function overrides/replaces this one?

        function onLoad() {
   document.addEventListener("deviceready", onDeviceReady, false);
  }

  // device APIs are available
  //
  function onDeviceReady() {
   // Register the event listener
   document.addEventListener("backbutton", onBackKeyDown, false);
  }

  // Handle the back button
  //
  function onBackKeyDown(e) {
   e.preventDefault();
   navigator.notification.confirm("×”×?×? ברצונ×? ×?צ×?ת?", onConfirm, "יצי×?×”", "יצי×?×”,ביטו×?"); 
  }
  function onConfirm(button) {
   if(button==2){//If User selected No, then we just do nothing
    return;
   }else{
    navigator.app.exitApp();// Otherwise we quit the app.
   }
  }

What happens here is that onLoad is called, and onDeviceReady is never called.

Itamar
  • 885
  • 1
  • 9
  • 17
  • It's not clear from your question if you tried to add `document.addEventListener("deviceready", yourCallbackFunction, false);` and it is not working – beaver Jan 27 '16 at 07:39
  • Where are you building your app from? – Jose Rojas Jan 27 '16 at 16:19
  • I did use **document.addEventListener ("deviceready", yourCallbackFunction, false);** @beaver – Itamar Jan 27 '16 at 16:26
  • I use Sencha to build the app before planting it in an empty phonegap project. Now I am using Android Studio to run it. @JoseRojas – Itamar Jan 27 '16 at 16:30
  • @Itamar, but the callBackFunction isn't invoked? could you post some relating code? – beaver Jan 27 '16 at 17:17
  • look into your android folder project a file called cordova.js you must import it for onDeviceReady function being called – Jose Rojas Jan 27 '16 at 17:20

1 Answers1

0

For onDeviceReady function being called you must import Cordova.js file.

check this issue maybe can help you.

Where do I find cordova.js?

Community
  • 1
  • 1
Jose Rojas
  • 3,490
  • 3
  • 26
  • 40