更新Android应用(不使用Google Play)

时间:2013-03-04 23:35:56

标签: android

我写了一个应用程序的Beta版本。它可以通过网络下载(我不会将其发布到Play Market)。当新版本发布时,是否可以在没有Play Market的情况下更新此应用程序?

5 个答案:

答案 0 :(得分:75)

绝对。但是,您需要构建一个机制,让您的应用程序调用服务器的主页,查看是否有更新版本的应用程序,如果有,请将其下拉并安装。一旦确定需要下拉更新,就可以使用类似于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);
}

答案 1 :(得分:13)

是的,这是可能的,这里大致是你可以做的:

  1. 获取当前应用程序版本代码

    PackageInfo packageInfo = getPackageManager().getPackageInfo(context.getPackageName(), 0);
    int curVersionCode = packageInfo.versionCode;
    
  2. 让服务器托管 apk 文件并创建一个只包含一个整数的简单纯文件,该文件代表最新的应用程序版本代码。

  3. 当应用程序启动时(或者每当您想要检查更新时),从服务器检索最新的versionCode(即通过HTTP请求)并将其与当前的应用程序版本进行比较。

    < / LI>
  4. 如果有新版本,请下载 apk 并安装它(将为用户提示对话框)。

  5. 编辑:

    您可以使用@Blumer的代码。

答案 2 :(得分:6)

但是请注意,用户必须在其设置中启用“允许安装非市场应用程序/未知来源”。

答案 3 :(得分:3)

仅供参考,我刚刚在http://blog.vivekpanyam.com/evolve-seamlessly-deploy-android-apps-to-users/?hn

了解了这一点
  

Evolve是Android开发者的一个库,可以让他们部署新的   应用程序的版本,无需通过Google Play或询问用户   下载更新。它的工作原理是使用反射和动态   字节码生成“欺骗”Android运行新代码。

虽然它是阿尔法,但似乎有可能通过很多箍。我怀疑它是否值得,除了恶意软件..

答案 4 :(得分:0)

Official support/library for In-app updates Google play core

  • 应用内更新是一项 Play 核心库功能,可提示活跃用户更新您的应用。 运行 Android 5.0(API 级别 21)或更高版本的设备支持应用内更新功能,并且要求您的应用使用 Play Core library 1.5.0 或更高版本。此外,只有 Android 移动设备、Android 平板电脑和 Chrome 操作系统设备支持应用内更新。

以下是更新流程的类型

  1. Flexible updates(示例屏幕)

enter image description here

  1. Immediate updates(示例屏幕)

enter image description here

Reference :-More about this topic