Search code examples
androidcordovamulti-device-hybrid-appsvisual-studio-cordova

Create a function that fires only once after app is installed on phone


I'm developing a mobile app using ApacheCordova/Phonegap. I need a function that sends a SMS to me once per install. If I put my function on "DeviceReady" it will be run each time the app opens. Is there any solution for a function to be run when app is installed OR when it runs for first time?

Any suggestion would be appreciated.


Solution

  • I added a field to the localstorage and on startup just check if that field exists. So something like this:

    if (window.localStorage.getItem("installed") == undefined) {
       /* run function */
       window.localStorage.setItem("installed", true);
    }
    

    Edit: The reason I prefer this over the other methods is that this works on iOS, WP, etc as well, and not only on android