How to configure an application to wait until the PhoneGap APIs are available?

When the web application is loaded, the PhoneGap app’s JavaScript code doesn’t have immediate access to the PhoneGap API’s. The native phonegap app container must complete its initialization process before it can respond to the phonegap APIs JavaScript calls. To accommodate this delay, the container must be instructed to notify the web app when phonegap APIs are available. After this ‘APIs available’ notification, the app can use the required APIs.

This notification is done through -> onload in the <body>

<body onload=”onBodyLoad()”>

//In onBodyLoad -> call onDeviceReady() when device is ready, when PhoneGap container finished initialization routines.

  function onBodyLoad()    {

     document.addEventListener(“deviceready” , onDeviceReady, false);

}

//onDeviceReady() -> do the action to be performed.

function onDeviceReady()   {

navigator.notification.alert (“PhoneGap ready”);

}

References

Essential of PhoneGap

Previous
Previous

JQuery DataTables

Next
Next

How does PhoneGap work?