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

4

My application will not 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 without spending anything, using free services (like Dropbox or the like). How to do this? Could you please help me? Explain in detail. Thank you in advance.

    
asked by anonymous 01.07.2014 / 01:03

2 answers

4

Well, basically I'll give you the 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 the software ok), you have a VersionPublish folder, inside it you can have an XML file, for example, containing the current version name, code number, publication date , etc.

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

So you have your application query the server.

Example:

Your application sends a request to the server informing the version (code number) of the currently installed application. The server verifies the currently published version is higher than the one reported by the requesting application.

If yes, it returns a true response (there you show the refresh 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, the user installs the APK normally.

Consider that you can not do the same type of update performed by the Play Store.

If you are afraid of getting your APK on your mobile phone, simply download it to an internal folder and then call the OS installation itself.

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

    
01.07.2014 / 13:38
1

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

If it does, 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);
}
    
26.08.2016 / 13:17