Reading config file from device

I am having trouble reading the www/config.xml file from Android device. I tried two different approaches. First, I tried using the $http service which was recommended in another thread to do. When that did not work I then tried to use the Cordova file plugin. The reason I am doing this is to try to get the version number from the www/config.xml file in the app. Below are both approaches:

  1. $http.get()

    url = ‘file:///android_asset/www/config.xml’
    .then ((data) ->
    versionNumber =<widget\s.*?\sversion=’"[’"]/)
    verNum = versionNumber[1]
    ), (err) ->
    # {“data”: null, “status”: 0, …}
    alert JSON.stringify err

  2. Cordova file plugin

    if ionic.Platform.isAndroid()
    path = 'file:///android_asset/www/'
    file = ‘config.xml’
    $cordovaFile.readAsText(path, file)
    .then ((data) ->
    alert JSON.stringify data
    ), (error) ->
    # I alert { code: 5 } which is an ENCODING_ERR
    alert JSON.stringify error

If you’re trying to get the app’s version number,

It seems that the plugin grabs the root config.xml file not the www/config.xml file.

the www/config.xml is an older, no longer supported file. The root config.xml should be all you need.

1 Like