Search code examples
cordovaphonegap

How to call a function when installing application in Cordova


I want to call a function when installing A Cordova/Phonegap application (for create database and insert records to that).

In fact I just wanna run this function only once.

Any suggestion?


Solution

  • You can use LocalStorage for that :

    document.addEventListener('deviceready', function()
    {
        if (typeof window.localStorage.getItem('firstTime') === 'undefined')
        {
            // Execute some code for the installation
            // ...
    
            window.localStorage.setItem('firstTime', 0);
        }
    });