+ Start a Discussion
Prakhar KPrakhar K 

In contact explorer app (Hybrid) (Android) onDeviceReady function is not firing?

After compiling and running the contact explorer sample app (hybrid), in index.html the onDeviceReady function is not firing nor it is giving any error in logCat in eclipse ADT?
I am using cordova 2.2.0.js using API 16 4.1.2 ?below is the code of index.html

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0; user-scalable=no" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">

    <link rel="stylesheet" href="jquery/jquery.mobile-1.3.1.min.css" />
    <script src="jquery/jquery-2.0.0.min.js"></script>
    <script src="jquery/jquery.mobile-1.3.1.min.js"></script>

<script src="cordova-2.2.0.js"></script>

    <script src="cordova.force.js"></script>

    <script src="forcetk.mobilesdk.js"></script>

      .logWindow {display:none; width:700px;}
      .logWindow > p {padding:0px; margin:0px; word-wrap:break-word;}


    // The version of the REST API you wish to use in your app.
    var apiVersion = "v28.0";

    var forcetkClient;
    var debugMode = true;
    var logToConsole = cordova.require("salesforce/util/logger").logToConsole;

    jQuery(document).ready(function() {
        //Add event listeners and so forth here
        logToConsole("onLoad: Hii jquery ready");
  document.addEventListener("deviceready",onDeviceReady,false);                             //not firing,no error in LogCat and in console//


    // When this function is called, Cordova has been initialized and is ready to roll
    function onDeviceReady() {
        logToConsole("onDeviceReady: Cordova ready");
  //Call getAuthCredentials to get the initial session credentials
        cordova.require("salesforce/plugin/oauth").getAuthCredentials(salesforceSessionRefreshed, getAuthCredentialsError);

        //register to receive notifications when autoRefreshOnForeground refreshes the sfdc session

        //enable buttons


    function salesforceSessionRefreshed(creds) {
        // Depending on how we come into this method, `creds` may be callback data from the auth
        // plugin, or an event fired from the plugin.  The data is different between the two.
        var credsData = creds;
        if (creds.data)  // Event sets the `data` object with the auth data.
            credsData = creds.data;

        forcetkClient = new forcetk.Client(credsData.clientId, credsData.loginUrl, null,
        forcetkClient.setSessionToken(credsData.accessToken, apiVersion, credsData.instanceUrl);

    function getAuthCredentialsError(error) {
        logToConsole("getAuthCredentialsError: " + error);
<!-- load our app-specific code -->

    <script src="/inline/inline.js">
     alert('invoking callMe of inline.js ...');

      <div data-role="page" data-theme="b" id="jqm-home">
          <div  data-role="header">
              <h1>Hybrid REST Explorer (SalesforceMobileSDK + Cordova + JQM)</h1>

          <div id="#content" data-role="content">

              <p><a href="#" id="link_fetch_device_contacts" data-role="button" data-inline="true">Fetch Device contacts</a></p>
              <p><a href="#" id="link_fetch_sfdc_contacts" data-role="button" data-inline="true">Fetch SFDC contacts</a></p>
              <p><a href="#" id="link_fetch_sfdc_accounts" data-role="button" data-inline="true">Fetch SFDC Accounts</a></p>
              <p><a href="#" id="link_reset" data-role="button" data-inline="true">Reset</a></p>

              <p><a href="#" id="link_logout" data-role="button" data-inline="true">Logout</a></p>

              <div id="div_device_contact_list"></div>
              <div id="div_sfdc_contact_list"></div>
              <div id="div_sfdc_account_list"></div>

              <p id="console" class="logWindow">