更新 Android 应用程序(无需访问 Google Play 商店) [英] Update an Android app (without Google Play store visit)

查看:165
本文介绍了更新 Android 应用程序(无需访问 Google Play 商店)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了该应用程序的 Beta 版.它将可以通过网络下载(我不会将其发布到 Play Market).新版本发布时,是否可以在不访问 Play Market 的情况下更新此应用程序?

I wrote a Beta version of the application. It will be available for download through the web (I will not publish it to the Play Market). Is it possible to update this application without Play Market visit when the new version will be released?

推荐答案

绝对可以.不过,您需要构建一种机制,让您的应用程序调用服务器的主页,找出是否有更新版本的应用程序,如果有,将其拉下并安装.一旦你确定你确实需要拉下更新,你可以用类似于这个 AsyncTask 的东西来做到这一点:

Absolutely. You will need to build a mechanism, though, for your app to call home to the server, find out if there's a newer version of the app, and if there is, pull it down and install it. Once you've determined that you do need to pull down an update, you can do that with something similar to this AsyncTask:

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

        int fileLength = connection.getContentLength();

        // download the file
        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("YourApp", "Well that didn't work out so well...");
        Log.e("YourApp", e.getMessage());
    }
    return path;
}

// begin the installation by opening the resulting file
@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("Lofting", "About to install new .apk");
    this.context.startActivity(i);
}

这篇关于更新 Android 应用程序(无需访问 Google Play 商店)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆