How to make a manual system to check for new updates?

Asked

Viewed 950 times

4

My app won’t be published on Google Play, so I need to make a system to check for new updates and download them, without relying on Google Play. And preferably free, using free services (like Dropbox or the like). How to do this? Could you please help me? Explain in detail. I thank you in advance.

  • But you want your app to automatically check for updates?

  • @Jorgeb. It was to check manually anyway. But it’s already solved! Thanks for the support.

2 answers

4


Well, basically I’ll give you an idea of how this works and you implement ok.

You must have a server where there is a file that tells you which version is currently published.

Example:

In the root folder of your server (server is ok software), you have a Versionpublish folder, inside it you can have an XML file, for example, containing the name of the current version, code number, publication date, etc.

And also, inside this root folder, the last APK file matches the description in XML.

So, you make your application query the server.

Example:

Your application sends a request to the server stating the version (code number) of the currently installed application. The server checks the currently published version is higher than that reported by the application that made the request.

If yes, it returns a true answer (then you show the update button, or a message to the user asking if he wants to update, etc).

When the user informs that they want to update, you send another request to the server requesting the download of the published file.

After downloading, user installs APK normally.

Consider that you cannot do the same update type performed by the Play Store.

If you are afraid of the user staying with your APK on the mobile phone, just download in an internal folder and then call the OS installation Intent itself.

This was a simple example! Consider all the engineering behind security, etc.

  • Nice example and idea! After a lot of research and intense searches, I found a solution: a simple bookstore to apply in my app, the Android Wversion Manager. Thanks for the support!

1

You need to build a mechanism for your app to call the server periodically and check if there is a new version.

If it exists, the app needs to download the update and install it with something similar to this Asynctask:

protected String doInBackground(String... sUrl) {
String path = "/sdcard/SeuApp.apk";
try {
    URL url = new URL(sUrl[0]);
    URLConnection connection = url.openConnection();
    connection.connect();

    int fileLength = connection.getContentLength();

    // baixar o arquivo
    InputStream input = new BufferedInputStream(url.openStream());
    OutputStream output = new FileOutputStream(path);

    byte data[] = new byte[1024];
    long total = 0;
    int count;
    while ((count = input.read(data)) != -1) {
        total += count;
        publishProgress((int) (total * 100 / fileLength));
        output.write(data, 0, count);
    }

    output.flush();
    output.close();
    input.close();
} catch (Exception e) {
    Log.e("SeuApp", "Não funcionou tão bem...");
    Log.e("SeuApp", e.getMessage());
}
return path;
}

// começar instalação abrindo o arquivo
@Override
protected void onPostExecute(String path) {
    Intent i = new Intent();
    i.setAction(Intent.ACTION_VIEW);
    i.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive" );
    Log.d("SeuApp", "Começando a instalação do .apk");
    this.context.startActivity(i);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.