Reading the ionic www / config.xml file from the device

I am having trouble reading the www / config.xml file from an Android device. I tried two different approaches. Firstly, I tried using the $ http service recommended in another thread. When this did not work, I tried to use the plugin for the Cordova file. The reason I'm doing this is to try to get the version number from the www / config.xml file in the application. 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) Cordon 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 
+6
source share
2 answers

Look at the / Android platforms and you will see that the file 'android_asset/www/config.xml' does not exist. You can try reading the file '/res/xml/config.xml' or try a different approach, for example, create a Cordova Hook .

Cordoba Hooks :

Cordoba Hooks are special scripts that can be added by application and plugin developers or even your own build system to customize cordova commands.

You can adapt to replace the text hook from this article or build the hook number based on the same hook.

UPDATE

To get only the version number of your application, you can use this plugin:

Cordova AppVersion Plugin

Cordova plugin for returning the version number of the current application

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

Also available with ngCordova

+2
source

ngCordova has a wide range of plugins for working with ionic ones. To get the version of the application, use the following command: 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; }); 
+1
source

Source: https://habr.com/ru/post/982628/


All Articles