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'
$http.get(url)
.then ((data) ->
versionNumber = data.data.match(/<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
return
), (error) ->
# I alert { code: 5 } which is an ENCODING_ERR
alert JSON.stringify error
Take a look to the folder platforms/android and you can see that the file 'android_asset/www/config.xml'
don't exists.
You could try reading the file '/res/xml/config.xml'
or you could try a different approach for example creating a Cordova Hook.
Cordova Hooks:
Cordova Hooks represent special scripts which could be added by application and plugin developers or even by your own build system to customize cordova commands.
You could adapt the replace text hook from this article or this build number hook based on the same hook.
UPDATE
To get only the version number of your app you could use this plugin:
Cordova AppVersion plugin
Cordova plugin to return the version number of the current app
https://github.com/whiteoctober/cordova-plugin-app-version
Is available also with ngCordova
ngCordova has a great set of plugins when working with ionic. To get the app version use this one: http://ngcordova.com/docs/plugins/appVersion/
I wanted to display the version number in my splash screen, so I used their example and added an event:
Inside $ionicPlatform.ready
callback:
$cordovaAppVersion.getVersionNumber().then(function (version) {
$rootScope.$broadcast("appVersionResolved", { version: appVersion });
}
In the splash screen controller:
$rootScope.$on("appVersionResolved", function(event, args) {
$scope.appVersion = args.version;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With