How to make PhoneGap Android app perform self-updating?

I have this situation - PhoneGap application works in Android. It uses an external API on my server. Perhaps I changed the structure of the API, so I will need to upgrade my mobile application to a newer version. Is there an automatic or semi-automatic way, how can I force update the Phonegap application on an Android phone?

I can display a message to the user that the application is out of date, and he should go to the Android Market and update the application from there, but I'm looking for another convenient way to force this update.

EDIT - Question Specification:

I am not looking for a way to load an external script when the application starts. I am looking for a solution for PhoneGap-Android, how to trigger an application update.

+6
source share
2 answers

Well, I finally found a solution to my problem.

I use this PhoneGap plugin to launch Android Intent, in particular its Intent.ACTION_VIEWS, described here in Android docs .

This successfully launches the Android Market app with the ability to update my app.

+4
source

you can load your javascript functions during initialization from your server. If you have jQuery, try the following:

<html> <head> <script type="text/javascript" charset="utf-8" src="jquery.js"></script> <script> function init() { $.getScript("http://yourserver.com/code.js", function(){} ); } function doSomething() { alert('sorry! functions not loaded!'); } </script> </head> <body onload="init()"> <input type=button value="doSomething();"> </body> </html> 

The code.js file is similar to

 function doSomething() { alert('Doing something wonderful'); } 
-1
source

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


All Articles