Search code examples
cordovaphonegap-pluginsphonegap-buildcordova-3

Phonegap - getting app information


I am using the next plugin to get information:

https://github.com/whiteoctober/cordova-plugin-app-version

with the next code:

var app_information = {};       

    cordova.getAppVersion.getAppName(function (app_name) {          
        app_information["app_name"] = app_name;
    });

    cordova.getAppVersion.getPackageName(function (app_package_name) {          
        app_information["app_package_name"] = app_package_name;
    });

    cordova.getAppVersion.getVersionCode(function (app_build_identifier) {          
        app_information["app_build_identifier"] = app_build_identifier;
    });

    cordova.getAppVersion.getVersionNumber(function (app_version) {         
        app_information["app_version"] = app_version;
    });

    alert(app_information["app_version"]); // getting undefind 

The problem is when I use alert inside the plugin functions I getting the result for example:

cordova.getAppVersion.getVersionNumber(function (app_version) {         
    alert(app_version);
});

but when I try to alert the final variable "app_information" I getting empty variable (no values inside the array)


Solution

  • You are trying to access the data outside the scope, that's the reason you are unable to alert it. simply declare a global variable and assign the data to it so that you can use it anywhere.

    var app_info = ''; 
    
    cordova.getAppVersion.getVersionNumber(function (app_version) {         
            app_info = app_version;
        });
    
    alert(app_info);