Software Archive
Read-only legacy content
17060 Discussions

Displaying version #

Hooman_F_1
Beginner
475 Views

Is there a way to get the project version #  (under build properties) so I can display it on my app's about page?

0 Kudos
6 Replies
Brandon_K_Intel
Employee
475 Views

There is not a way to dynamically get the app version from the code. This would be something you would have to statically type in each time. My question is, why would you want to do this? When you submit to any app store, it is going to make you provide a version number. This would be visible to your users via the operating system. 

0 Kudos
Swati_S_Intel1
Employee
475 Views

Hello Hooman,

You can access the version number in your code. Version number is saved in the config.xml file. The "version" attribute in the second line of config.xml file gives you the version number.

<widget xmlns="http://www.w3.org/ns/widgets" xmlns:intelxdk="http://xdk.intel.com/ns/v1" id="xdk.sample.helloworld" version="0.0.1" android-versionCode="1">

You can access it by loading XML document through XMLHttpRequest synchronous call, although you have to check for device type to load platform specific config.xml. For e.g. for Android, it is intelxdk.config.android.xml, for iOS it is intelxdk.config.iOS.xml etc.

Swati

 

0 Kudos
Hooman_F_1
Beginner
475 Views

Ok, thanks.  I'll look into using the config file.

Ps: One reason besides aesthetics for an about page might be  to send the version to the backend so that old clients are invalidated / stopped from accessing the backend APIs.

0 Kudos
Swati_S_Intel1
Employee
475 Views

Yes, perfectly valid reason. 

Here is a snippet that I quickly tried for Android. In actual app you have to detect the device OS and pick the xml file accordingly.

if (window.XMLHttpRequest) {
  xhttp=new XMLHttpRequest();  
  xhttp.open("GET","intelxdk.config.android.xml",false);
  xhttp.setRequestHeader("Content-Type","text/xml");
  xhttp.send(null);
  var xmlDoc = xhttp.responseXML;
  x = xmlDoc.getElementsByTagName('widget');
  var vernumber = x[0].getAttribute('version');
  alert(vernumber);
}

 

Swati

0 Kudos
Hooman_F_1
Beginner
475 Views

@SWATI, I am getting a null for xmlDoc.  I suspect that's because the intelxdk.config.ios.xml (in my case) is outside the www folder.  Is your config file inside the www folder? 

0 Kudos
Hooman_F_1
Beginner
475 Views

Any update here?  I have verified it's the issue with the config file being outside of the www folder.  If I copy the file inside www, then the SWATI's code runs.  Any idea how to get XDK to move these files into www or access them outside www folder?

0 Kudos
Reply